PHPMailer 发送邮件提示 553 Mail from must equal authorized user 的原因是 SMTP 服务器用户名与发件人邮箱不一致,修改成相同即可解决这个问题。
/** *系统邮件发送函数 *@paramstring$tomail 接收邮件者邮箱 *@paramstring$name 接收邮件者名称 *@paramstring$subject 邮件主题 *@paramstring$body 邮件内容 *@paramstring$attachment 附件列表 *@returnboolean *@authorstatic7<static7@qq.com> */ functionsend_mail($tomail,$name,$subject='',$body='',$attachment=null){ $mail=newPHPMailerPHPMailerPHPMailer(); $mail->CharSet='UTF-8'; $mail->IsSMTP(); $mail->SMTPDebug=0; $mail->SMTPAuth=true; $mail->SMTPSecure='ssl'; $mail->Host="smtp.163.com"; $mail->Port=465; $mail->Username="test@163.com";//SMTP 服务器用户名 $mail->Password="******";//SMTP 服务器密码与邮箱密码不同 $mail->SetFrom('test@163.com','测试邮件');//此处的邮箱应该与上面的 SMTP 服务器用户名一致 $replyEmail=''; $replyName=''; $mail->AddReplyTo($replyEmail,$replyName); $mail->Subject=$subject; $mail->MsgHTML($body); $mail->AddAddress($tomail,$name); if(is_array($attachment)){ foreach($attachmentas$file){ is_file($file)&&$mail->AddAttachment($file); } } return $mail->Send()?true:$mail->ErrorInfo; }
本文为原创文章,版权归主机之家测评所有,欢迎分享本文,转载请保留出处!