phpemailsmtpphpmailer
以下是My Code
錯誤提示資訊為:
SMTP server error: Error: send HELO/EHLO first
如果把SMTPAuth改為true,錯誤為
SMTP Error: Could not authenticate. Mail errorSMTP Error: Could not authenticate.
請教大神是什麼原因?
是不是還需要哪些設定?還是phpmailer用得不對?
謝謝!
function sendmail($to,$subject,$msg)
{
require_once "PHPMailer/class.phpmailer.php";
include('PHPMailer/class.smtp.php');
$mail = new PHPMailer(); //建立執行個體$mail -> CharSet='utf-8'; //設定字元集$mail -> SetLanguage('en','include/PHPMailer/language/'); //設定語言類型和語言檔案所在目錄$mail -> IsSMTP(); //使用SMTP方式發送$mail -> SMTPAuth = false; //設定伺服器是否需要SMTP身分識別驗證$mail -> Host = "smtp.163.com"; //SMTP 主機地址$mail -> Port = 25; //SMTP 主機連接埠$mail -> From = "ajw211@163.com"; //寄件者EMAIL地址$mail -> FromName = 'ajw211'; //寄件者在SMTP主機中的使用者名稱$mail -> Username = "anthony"; //寄件者的姓名$mail -> Password = "**************"; //寄件者在SMTP主機中的密碼$mail -> Subject = $subject; //郵件主題$mail -> AltBody = 'text/html'; //設定在郵件內文不支援HTML時的備用顯示$mail -> Body = $msg;//郵件內容做成$mail -> IsHTML(true); //是否是HTML郵件$mail -> AddAddress($to,'zy10601'); //收件者的地址和姓名$mail -> AddReplyTo($to,'zy10601'); //收件者回複時回複給的地址和姓名//$mail -> AddAttachment('include/id.csv','att.csv');//附件的路徑和附件名稱if(!$mail->Send()){ echo "Mail error" . $mail->ErrorInfo;}else{ echo "suucceed!!";}
}
$to = $_POST['toemail'];
$subject = $_POST['title'];
$msg = $_POST['content'];
sendmail($to,$subject,$msg);