PHPMailer 在 localhost 上工作而不是在 staging 上工作,两者的配置相同

PHPMailer working on localhost and not on staging, same config on both

我的 phpmailer 有问题,在我的本地主机上一切正常,我从我的 php 应用程序收到邮件但是当我使用相同的 docker 容器时我的暂存环境 phpmailer return 成功,但我的邮箱中再也收不到邮件了:/

这是一些代码:

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

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

$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:<admin@thomasmorice.com>
2017-08-09 07:37:48 CLIENT -> SERVER: RCPT TO:<t.morice4@gmail.com>
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: t.morice4@gmail.com
2017-08-09 07:37:48 CLIENT -> SERVER: From: admin@thomasmorice.com
2017-08-09 07:37:48 CLIENT -> SERVER: Subject: New mail
2017-08-09 07:37:48 CLIENT -> SERVER: Message-ID:<066e8c3f0b442dca0c4fdabf896a0d1b@staging.thomasmorice.com>
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 : sendermail@testmail.com
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."}

我真的坚持这个,因为我在本地主机和服务器 docker 容器上有完全相同的配置) 也许是因为我的 MX 在 dns 中?我迷路了有人知道吗?

非常感谢您的帮助

-- 编辑

经过一些研究发现有些奇怪,使用 this website 通过 MX 工具测试 MX 查找,我发现当我 运行 使用我的本地服务器进行测试时:thomasmorice.dev,我找到了一个 dns 记录:/ 这怎么可能,因为这是我的本地服务器:/ 对 staging.thomasmorice.com 做同样的事情,我得到一个 DNS 错误。在我看来这应该是相反的。我真的很困惑

<?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'];

试试这个。它可能对你有用。

好吧,显然我最后尝试了一下,看起来它现在可以正常工作了。我讨厌它发生的时候.. 就像,我最近没有更改任何与此邮件功能或任何内容相关的内容:/但它确实有效.. 所以认为它已修复 :D 感谢大家的帮助!