2017-07-06 114 views
0

我有電子郵件服務和即時消息服務器嘗試發送使用PHPMailer的郵件是這樣的:PHP的郵件沒有顯示錯誤,但不發送電子郵件

include('config/class_phpmailer.php'); 

$email = new PHPMailer(); 

$email->IsSMTP(); 
$email->SMTPAuth = true; 
$email->Host = 'smtp-mail.outlook.com'; // netcabo 
$email->Port = 587; 
$email->SMTPKeepAlive = true; 
$email->Username = [email protected]; 
$email->Password = my_password; 
$email->SMTPSecure = 'tls'; 
$email->From  = [email protected]; 
$email->FromName = 'my_name'; 
$email->Subject = $subject; 
$email->Body  = $message; 

// Set the Atatchment 
if($attach) { 
    $email->AddAttachment($attach); 
} 
// set the emails to send the message 
foreach($emails_to as $mail) { 
    $email->addAddress($mail); 
} 
// send the email 
if(!$email->Send()) { 
    echo "Message was not sent <br />PHPMailer Error: " . $email->ErrorInfo; 
} 
else { 
    echo "Message has been sent"; 
} 

這工作完全在本地主機上,但是當我把它上傳到服務器,它給我一個錯誤說:「消息未發送 PHPMailer錯誤:SMTP連接()失敗」。所以,我試過改變主機,端口,用戶,並從該服務器傳遞給我的電子郵件帳戶,並沒有發生任何事情。沒有錯誤,沒有「消息已發送」,沒有任何...電子郵件沒有發送。只是一個空白頁面。

我在做什麼錯了?提前致謝。

+0

搜索錯誤。按照錯誤消息中的疑難解答鏈接 - 如果沒有鏈接,則運行PHPMailer的舊版本並需要更新。 – Synchro

+0

@eskimopest你沒有包含這個類'class.smtp.php' –

+0

[PHPMailer和SMTP:Mail從遠程服務器發送時永遠不會顯示,可在本地機器上正常工作](https://stackoverflow.com/問題/ 756899/phpmailer-and-smtp-mail-never-show-up-when-sent-from-remote-server-works-fine) – Synchro

回答

0

如果你想抓住你後,才能做到這一點

$mail = new PHPMailer(true); 
// the true param means it will throw exceptions on errors, which we need to catch 
相關問題