2013-10-12 77 views
0

所以我把所有的文件,並更改SMTP信息,但由於某種原因,我無法讓它的工作。這裏是PHP的樣子..PHPMailer不會工作?

<?php 
require 'phpmailer/class.phpmailer.php'; 

$mail = new PHPMailer; 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp.mail.yahoo.com'; // Specify main and backup server 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = 'MYEMAILADDRESS';       // SMTP username 
$mail->Password = 'MYEMAILPASSWORD';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable encryption, 'ssl' also accepted 

$mail->From = '[email protected]'; 
$mail->FromName = 'Mailer'; 
$mail->addAddress('[email protected]', 'Josh Adams'); // Add a recipient 
$mail->addAddress('[email protected]');    // Name is optional 
$mail->addReplyTo('[email protected]', 'Information'); 
$mail->addCC('[email protected]'); 
$mail->addBCC('[email protected]'); 

$mail->WordWrap = 50;         // Set word wrap to 50 characters 
$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
    exit; 
} 

echo 'Message has been sent'; 
?> 

我打開頁面時出現此錯誤。

SMTP錯誤:無法連接到SMTP主機。郵件無法發送。郵件錯誤:SMTP錯誤:無法連接到SMTP主機。

請幫忙!

+0

試圖與雅虎本身連接?或任何其他服務器? –

+0

我不明白你在問什麼。 –

+0

你可以ping smtp.mail.yahoo.com嗎? – pregmatch

回答

0

我注意到您正在使用TLS SMTPSecure。

嘗試到您的SMTP端口設置爲587或465

$mail->Port = 465; //SSL 
$mail->Port = 587; //TLS 

順便說一句,嘗試ping你的SMTP服務器或執行一個telnet嘗試每一個端口(587或465),也許有一個代理通過該端口阻止您的連接。

0

對於$ mail-> SMTPSecure ='tls'; 嘗試$ mail-> Port = 587;