2017-05-05 40 views
0

下面的函數來發送電子郵件,但有任何郵件或錯誤:PHPMailer的郵件無法發送,並沒有得到任何錯誤

function send_Email($email, $subject, $body ,$cc = '') 
{ 
    $this->Log("Sending email with To: ". $email. " <br>Subject: ". $subject ."  <br>Body: ".$body); 

    $mail = new PHPMailer(); 
    $mail->IsHTML(true); 
    $mail->IsSMTP(); 
    $mail->CharSet = "utf-8"; 
    $mail->SMTPAuth = true; 
    $mail->SMTPSecure = "tls"; 
    $mail->Host  = email_host; 
    $mail->Username = email_username; 
    $mail->Password = email_password; 
    $mail->SetFrom('[email protected]', 'zzz Support'); 
    $mail->AddReplyTo('[email protected]', 'zzz Support'); 
    $mail->AddAddress($email); 
    $mail->AddBCC('[email protected]'); 
    $mail->AddBCC('[email protected]'); 
    if(!empty($cc)) { 
     $mail->addCC($cc); 
    } 
    $mail->Subject = $subject; 
    $mail->Body  = $body;  

    echo "<pre>"; print_r($mail);echo "</pre>"; 
    $response = $mail->Send(); 
    var_dump($response); 

    return $response; 
} 

調試:在調試模式下得不到錯誤 [ERROR_COUNT:保護] => 0

+0

您在哪裏發送郵件?您可以先使用[FakeSMTP](https://github.com/Nilhcem/FakeSMTP)等工具測試轉儲郵件。 –

+0

這是'回聲'

"; print_r($mail);echo "
「;'打印什麼?或'var_dump'? –

+0

var_dump(false)....... – sudhir

回答

0

這將有助於閱讀文檔,並將代碼基於提供的示例,其中顯示如何獲取有關錯誤的信息,並顯示調試輸出。你沒有得到任何輸出,因爲你沒有要求任何。從自述文件中的示例:

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

這會告訴您任何發送失敗的原因。要啓用SMTP調試輸出,請執行以下操作:

$mail->SMTPDebug = 2;