使用php发邮件的简单例子
```
require 'phpmailer/JPhpMailer.php';
$mailto='moozik@qq.com'; //收件人
$subject='表格测试'; //邮件主题
//$body=date('时间:Y年m月d日 H:i:s'); //邮件内容
$body=file_get_contents('table2.htm'); //使用html页面作为正文内容
sendmailto($mailto,$subject,$body);
echo 'finish'.date('时间:Y年m月d日 H:i');
function sendmailto($mailto, $mailsub, $mailbd)
{
$mailer = new JPhpMailer;
$mailer->IsSMTP();
$mailer->Host = 'mail.xiji.com';
$mailer->SMTPAuth = true;
$mail_from = 'wang.yusen@xiji.com';
$mailer->From = $mail_from;
$mailer->AddReplyTo($mail_from);
$mailer->AddAddress($mailto);
$mailer->FromName = $mail_from;
$mailer->Username = 'moozik@qq.com';
$mailer->Password = 'pass';
$mailer->SMTPDebug = true;
$mailer->CharSet = 'UTF-8';
$mailer->Subject = $mailsub;
$mailer->Body = $mailbd;
$mailer->AddAttachment('..\make_excel.xlsx','我的附件.xlsx'); // 添加附件,并指定名称
$mailer->IsHTML(true); //支持html格式内容
$mailer->Body = $mailbd;
$mailer->Send();
}
```

附件下载:[phpmailer.rar](https://static.moozik.cn/usr/uploads/phpmailer.rar)

最后修改:2019 年 11 月 13 日
如果觉得我的文章对你有用,请随意赞赏