在PHP脚本中发送邮件除了使用自带的mail()函数,还可以使用流行的phpmailer插件,不近配置方便而且功能强大。
- 下载phpmailer所需文件phpmailer文件下载
- 发送邮件:
require('class.phpmailer.php');
require('class.smtp.php');
$mail = new PHPMailer();//初始化
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->CharSet = 'utf-8';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';//'tls'根据设置的邮箱进行配置;
$mail->Host = 'smtp.mxhichina.com';
$mail->IsHTML(FALSE);
$mail->FromName = "DF";
$mail->Username = 'xxxxx@xxx.com';//用户名,一般与邮箱一致
$mail->From = 'xxxxx@xxx.com';//邮箱
$mail->Password = '12345';//密码
$mail->Subject = 'Prediction result';//邮件主题
$mail->AddAddress($email);//发送邮箱地址
$mail->AddAttachment('drugFitness.txt','PredictionResult.txt');//添加附件,并且重命名
$mail->Body='Here is your prediction result , please see the attachment'.PHP_EOL.'Thank you for your support';//邮件主体
$mail->Send();//发送