2014-04-12 60 views
0

我想使用PHP郵件發送一些郵件,無聊的事情是,第一次發送一封電子郵件eas,我不知道我做了什麼讓這段代碼現在失敗。如何設置PHPMailer SMTP

錯誤:SMTP服務器錯誤:驗證所需

require("../mailer/class.phpmailer.php"); 
$mail = new PHPMailer(); 
$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Host  = "smtpout.secureserver.net"; // SMTP server 
$mail->From  = "site email"; 
$mail->AddAddress("useremail"); 
$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.'; 
} 

我與GoDaddy託管。

+1

檢查這個答案了。一般來說,你需要在使用SMTP時使用用戶名和密碼。如果你發送的第一封郵件正常工作,那麼可能是通過服務器上的'localhost' MTA? http://stackoverflow.com/questions/15087913/sending-email-from-form-through-gmail-smtp-on-godaddy – JakeGould

回答

0

感謝傑克。

因爲有人再次經歷這個問題,這裏是我放入我的代碼。

CODE

require("class.phpmailer.php"); 
$mail = new PHPMailer(); 
$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Host  = "smtpout.secureserver.net"; // SMTP server 
$mail->Username = "[email protected]"; 
$mail->Password = "pwd"; 
$mail->SMTPAuth = true;  
$mail->Port  = 25; 
$mail->SMTPDebug = 2; /// i guess this is for reporting... 
$mail->From  = "[email protected]"; 
$mail->AddAddress("recipient email"); 
$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.'; 
}