Search code examples
phpdockerphpmailerstaging

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


I have a problem with phpmailer, everything is fine on my localhost, I get the mail back from my php application but when I use the same docker container on my staging environment, the phpmailer return success but I get no mail in my mailbox anymore :/

Here is some code :

//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);

Here is the response I have on the server :

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."}

I'm really stuck on this because I have exactly the same configuration on localhost and on the server docker container) Maybe it is because of my MX in the dns ? I'm lost do someone have a clue ?

Thanks a lot for your help

-- edit

Something weird after some research, using this website to test the MX lookup with the MX tool, I see that when I run the test with my local server : thomasmorice.dev, I get a dns record found :/ how can this be since this is my local server :/ Doing the same with staging.thomasmorice.com, I get a DNS error.. In my opinion this should be the other way around.. I'm really confused


Solution

  • Ok so apparently I gave it a last try, and it looks like it is working right now. I hate when it happened.. Like, I haven't changed anything recently that is related to this mail function or anything :/ but it just work.. So consider it fixed :D Thanks for your help everyone !