2010-08-19 156 views
1

可以請一些建議一個代碼我送使用雅虎smatp,和PHP郵件發送郵件..嘗試使用雅虎SMTP在PHP

require("class.phpmailer.php"); // be sure to change this to your location! 

$mail = new PHPMailer();  
$mail->IsSMTP(); 
$mail->SMTPAuth = true; // enable SMTP authentication 
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier  

$mail->Host = "smtp.mail.yahoo.com"; // sets yahoo as the SMTP server  
$mail->Port = 25; // set the SMTP port  
$mail->Username = "[email protected]"; // yahoo username  
$mail->Password = "password"; // yahoo password 

$mail->From = "[email protected]"; 
$mail->FromName = "myname";  
$mail->AddAddress("[email protected]");  
$mail->Subject = "Test PHPMailer Message";  
$mail->Body = "Hi! \n\n This was sent with phpMailer_example3.php."; 

if(!$mail->Send()) { 

    echo 'Message was not sent.';  
    echo 'Mailer error: ' . $mail->ErrorInfo; 

} else { 

    echo 'Message has been sent.'; 

} 

此代碼是給我errrors「無法連接到SMTP主機」

+0

您應該注意,舊的Yahoo Mail(@ yahoo.com)地址不支持SMTP ...您必須購買他們的高級選項才能支持SMTP。但是新的y7mail不需要購買高級計劃就可以支持SMTP。 – 2010-08-19 05:57:53

+1

連續第3行[想使用雅虎smtp從php發送郵件](http://stackoverflow.com/questions/3512204/want-to-send-mails-from-php-using-yahoo-smtp) – 2010-08-19 06:09:37

+0

不管你信不信,它實際上是第五次普拉米提出了這個問題的一些變種,上校。 – Shabbyrobe 2010-08-19 06:16:08

回答

0

許多網站提供SMTP不支持SSL(SMTP-S)。如果支持通常是在不同的端口,比如465連接到465經常會失敗的。嘗試註釋掉

$mail->SMTPSecure = "ssl" 

也試試f首先沒有驗證,以確保連接的工作。