2017-08-09 55 views
0

我有一個phpmailer的問題,我的本地主機上的一切都很好,我從我的PHP應用程序獲取郵件,但是當我在我的臨時使用相同的碼頭容器時環境中,PHPMailer的回報成功,但我得到了我的郵箱裏沒有郵件了:/PHPMailer在本地主機上工作,而不是在分期上,同樣的配置都在

下面是一些代碼:

//create an instance of PHPMailer 
$mail = new PHPMailer(); 

$mail->IsSMTP(); 
$mail->Host='ssl0.ovh.net'; 
$mail->Port = 465;  
$mail->Username = '[email protected]';  
$mail->Password = 'mypassword';   
$mail->SMTPAuth = true; 
$mail->SMTPSecure = 'ssl'; 
$mail->Priority = 3; 
$mail->CharSet = "ISO-8859-1"; //ISO-8859-1 _ utf-8 
$mail->setFrom('[email protected]'); 
$mail->AddAddress('[email protected]'); 

$mail->Subject='New mail'; 
$mail->Body = " 
    Name: " . $_POST['inputName'] . "\r\n 
    Mail : " . $_POST['inputEmail'] . "\r\n 
    Message: \r\n\r\n" . stripslashes($_POST['inputMessage']); 
$mail->SmtpClose(); 

if(!$mail->send()) { 
    $data = array('success' => false, 'message' => 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo); 
    echo json_encode($data); 
    exit; 
} 

$data = array('success' => true, 'message' => 'Thanks! We have received your message.'); 
echo json_encode($data); 

這裏是我的服務器上的響應:

2017-08-09 07:37:48 CLIENT -> SERVER: EHLO staging.thomasmorice.com 
2017-08-09 07:37:48 CLIENT -> SERVER: AUTH LOGIN 
2017-08-09 07:37:48 CLIENT -> SERVER: aGD76QHRob21hc21efmljZSaajb20= 
2017-08-09 07:37:48 CLIENT -> SERVER: QnhuNnJDWW5lOp8A 
2017-08-09 07:37:48 CLIENT -> SERVER: MAIL FROM:<[email protected]> 
2017-08-09 07:37:48 CLIENT -> SERVER: RCPT TO:<[email protected]> 
2017-08-09 07:37:48 CLIENT -> SERVER: DATA 
2017-08-09 07:37:48 CLIENT -> SERVER: Date: Wed, 9 Aug 2017 07:37:48 +0000 
2017-08-09 07:37:48 CLIENT -> SERVER: To: [email protected] 
2017-08-09 07:37:48 CLIENT -> SERVER: From: [email protected] 
2017-08-09 07:37:48 CLIENT -> SERVER: Subject: New mail 
2017-08-09 07:37:48 CLIENT -> SERVER: Message-ID:<[email protected]> 
2017-08-09 07:37:48 CLIENT -> SERVER: X-Priority: 3 
2017-08-09 07:37:48 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.22 (https://github.com/PHPMailer/PHPMailer) 
2017-08-09 07:37:48 CLIENT -> SERVER: MIME-Version: 1.0 
2017-08-09 07:37:48 CLIENT -> SERVER: Content-Type: text/plain; charset=ISO-8859-1 
2017-08-09 07:37:48 CLIENT -> SERVER: 
2017-08-09 07:37:48 CLIENT -> SERVER: 
2017-08-09 07:37:48 CLIENT -> SERVER:  Name: thomas test mail 
2017-08-09 07:37:48 CLIENT -> SERVER: 
2017-08-09 07:37:48 CLIENT -> SERVER:  Mail : [email protected] 
2017-08-09 07:37:48 CLIENT -> SERVER: 
2017-08-09 07:37:48 CLIENT -> SERVER:  Message: 
2017-08-09 07:37:48 CLIENT -> SERVER: 
2017-08-09 07:37:48 CLIENT -> SERVER: test mail 
2017-08-09 07:37:48 CLIENT -> SERVER: 
2017-08-09 07:37:48 CLIENT -> SERVER: . 
2017-08-09 07:37:48 CLIENT -> SERVER: QUIT 
{"success":true,"message":"Thanks! We have received your message."} 

我真的被困在這個,因爲我有完全相同的配置本地主機和服務器碼頭容器) 也許是因爲我的MX在DNS?我迷路了有人有線索嗎?

非常感謝您的幫助

- 編輯

事情經過一番研究,怪異,使用this website測試MX查找與MX的工具,我看到,當我運行測試與本地服務器:thomasmorice.dev,我得到一個DNS記錄發現:/這怎麼可能,因爲這是我的本地服務器:/ 做同樣的staging.thomasmorice.com,我得到一個DNS錯誤..在我看來這應該是反過來..我真的很困惑

+0

不知道它是否重要,但您在發送電子郵件之前關閉了SMTP連接? '$ mail-> SmtpClose();' – Matt

+0

噢,這很奇怪,我不得不承認:/ 我已經刪除了這行......但仍然有相同的問題:/ –

+0

您可以嘗試閱讀[PHPMailer疑難解答指南] (https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting)。如果你設置了'SMTPDebug = 2',你會看到服務器在說什麼。另外,您需要更新PHPMailer。 – Synchro

回答

0

好吧,顯然我給了它最後一次嘗試,它看起來像它現在正在工作。我討厭它發生的時間.. 像我最近沒有改變任何與此郵件功能有關的任何東西:/但它只是工作。 所以認爲它是固定的:D感謝您的幫助每個人!

+0

很高興看到它的修復。標記自己爲答案:) – Matt

-1
<?php 
require 'phpmailer/PHPMailerAutoload.php'; 

function sendMail($name,$maill,$message) 
{ 
    $url=$_SERVER['HTTP_REFERER']; 
    $mail = new PHPMailer; 
    $msg = wordwrap($message,70); 
    $mail->Debugoutput = 'html'; 
    // Enable verbose debug output 

    $mail->isSMTP();          // Set mailer to use SMTP 
    $mail->Host = 'smtp.gmail.com';      // Specify main and backup SMTP servers 
    $mail->SMTPAuth = true;        // Enable SMTP authentication 
    $mail->Username = 'xxx';     // SMTP username 
    $mail->Password = 'xxx';       // SMTP password 
    $mail->SMTPSecure = 'tls';       // Enable TLS encryption, `ssl` also accepted 
    $mail->Port = 587;         // TCP port to connect to 
    $mail->From = $maill; 
    $sujet=$name; 

    $mail->addAddress($maill);    // Name is optional 
    $mail->Subject = $sujet; 
    //$mail->Body = ; 
    $message=' 

    </html> 
     '; 

    $mail->MsgHTML(
    $message 
    ); 

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

$url=$_SERVER['HTTP_REFERER']; 

試試這個。它可能適合你。

+0

感謝您的建議,我試了一下,但不幸的是它不工作.. 其實,我們甚至在設置它後不使用'$ url'變量, t知道這應該如何工作tbh:/ –

+0

您使用的是什麼版本的phpMailer?無論如何嘗試改變這個$ mail-> SMTPSecure ='tls';或者可能是主機的防火牆阻止發送電子郵件 –

+0

不要發佈隨機代碼而不解釋*爲什麼*它解決了OP的問題,在這種情況下它不會。 – Synchro

相關問題