我想發送郵件PHP
。我爲本地主機和服務器使用相同的代碼。但是,當我使用服務器上的代碼,它似乎並沒有工作:在PHP發送郵件:SMTP錯誤:無法驗證
SMTP Error: Could not authenticate. Message was not sent.Mailer error: SMTP Error: Could not authenticate.
這是我的代碼供您參考。
require("class.phpmailer.php"); // path to the PHPMailer class
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myname"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = "[email protected]";
$mail->AddAddress("[email protected]");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
我做了很多搜索,沒有彈出。任何幫助將不勝感激。
你確定你已經給出正確的gmail ID和密碼嗎? –
是的!它從本地主機發送郵件,但不從服務器發送。 –
嘗試添加這個'$ mail-> SMTPSecure =「ssl」;' –