Search code examples
phpphpmailer

PHPMailler is not working in some cases


I am sending mail with PHPmailer. The mail I send is working on Gmail. But it does not work in the account on mail.com. Does anyone know why? The result seems to be successful. But mail is not coming.

Example not working: [email protected]

Note: I'm using the same settings. My mail server on another server.

If the code I'm using is :

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPAuth = true; // authentication enabled
$mail->SetLanguage("tr", "class/language");
$mail->CharSet    = "utf-8";
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host       = "example";
$mail->Port       = 25; // or 465
$mail->IsHTML(true);
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
$mail->Username    = "[email protected]";
$mail->Password    = "example";
$mail->SetFrom($To[1], $To[0]);
$mail->Subject = 'example';

$mail->Body = 'example';
$mail->AddAddress($From[1], $From[0]);

if ($mail->Send()) {
    echo 'success';
} else {
    echo $mail->ErrorInfo;
}

I was also redirected to my server CloudFlare.

PHPMailer Logs Output:

2018-04-24 11:24:49 SERVER -> CLIENT: 220 centos.controlsunucu.com ESMTP Postfix
2018-04-24 11:24:49 CLIENT -> SERVER: EHLO oxyn.org
2018-04-24 11:24:49 SERVER -> CLIENT: 250-centos.controlsunucu.com
                                      250-PIPELINING
                                      250-SIZE 10240000
                                      250-ETRN
                                      250-STARTTLS
                                      250-AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN
                                      250-ENHANCEDSTATUSCODES
                                      250-8BITMIME
                                      250 DSN
2018-04-24 11:24:49 CLIENT -> SERVER: STARTTLS
2018-04-24 11:24:49 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2018-04-24 11:24:49 CLIENT -> SERVER: EHLO oxyn.org
2018-04-24 11:24:49 SERVER -> CLIENT: 250-centos.controlsunucu.com
                                      250-PIPELINING
                                      250-SIZE 10240000
                                      250-ETRN
                                      250-AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN
                                      250-ENHANCEDSTATUSCODES
                                      250-8BITMIME
                                      250 DSN
2018-04-24 11:24:49 CLIENT -> SERVER: AUTH CRAM-MD5
2018-04-24 11:24:49 SERVER -> CLIENT: 334 PDg0NDE4Mjc5NS4xNDYxOTU4NkBjZW50b3MuY29udHJvbHN1bnVjdS5jb20+
2018-04-24 11:24:49 CLIENT -> SERVER: aW5mb0BkaXN0aWxlaWNraS5jb20gYWQ1MmQ2YjZjZTkzZTE3OTMzZDU5ZGNmNzZmNTJlYWY=
2018-04-24 11:24:49 SERVER -> CLIENT: 235 2.7.0 Authentication successful
2018-04-24 11:24:49 CLIENT -> SERVER: MAIL FROM:<[email protected]>
2018-04-24 11:24:49 SERVER -> CLIENT: 250 2.1.0 Ok
2018-04-24 11:24:49 CLIENT -> SERVER: RCPT TO:<[email protected]>
2018-04-24 11:24:49 SERVER -> CLIENT: 250 2.1.5 Ok
2018-04-24 11:24:49 CLIENT -> SERVER: DATA
2018-04-24 11:24:49 SERVER -> CLIENT: 354 End data with <CR><LF>.<CR><LF>
2018-04-24 11:24:49 CLIENT -> SERVER: Date: Tue, 24 Apr 2018 14:24:49 +0300
2018-04-24 11:24:49 CLIENT -> SERVER: To: =?utf-8?Q?=C3=96zg=C3=BCr_Can_KARAG=C3=96Z?= <[email protected]>
2018-04-24 11:24:49 CLIENT -> SERVER: From: =?utf-8?Q?=C3=96zg=C3=BCr_Can_KARAG=C3=96Z?= <[email protected]>
2018-04-24 11:24:49 CLIENT -> SERVER: Subject: Example
2018-04-24 11:24:49 CLIENT -> SERVER: Message-ID: <[email protected]>
2018-04-24 11:24:49 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.22 (https://github.com/PHPMailer/PHPMailer)
2018-04-24 11:24:49 CLIENT -> SERVER: MIME-Version: 1.0
2018-04-24 11:24:49 CLIENT -> SERVER: Content-Type: text/html; charset=utf-8
2018-04-24 11:24:49 CLIENT -> SERVER:
2018-04-24 11:24:49 CLIENT -> SERVER: Example
2018-04-24 11:24:49 CLIENT -> SERVER:
2018-04-24 11:24:49 CLIENT -> SERVER: .
2018-04-24 11:24:50 SERVER -> CLIENT: 250 2.0.0 Ok: queued as 918D133B8F
2018-04-24 11:24:50 CLIENT -> SERVER: QUIT
2018-04-24 11:24:50 SERVER -> CLIENT: 221 2.0.0 Bye

Solution

  • Set $mail->SMTPDebug = 2 to see the SMTP conversation, so you can be absolutely sure messages are being accepted and that you're not missing any interesting responses from the server. Beyond that, check your spam folder, and if your ISP is black-holing your messages, complain to them.

    Your use of $From and $To looks to be the wrong way around, and it's not possible to tell if they are using user-supplied values - allowing a user to supply an address that you use as a From address is a sure way to get your email blocked or spam filtered since it's forgery and will break SPF and DMARC checks.

    On the certificate front, that your site is using Cloudflare has nothing to do with the certificates used for mail.com's mail servers. You should only disable certificate checks if you have a very specific reason for doing so - "because it makes it work" is not a valid reason.

    Update:

    You're sending from a gmail address without sending through gmail - that will fail SPF checks. If you want to send From a gmail address, you must send through gmail, not your ISP.

    Unlikely to be a factor here, but you're using an old version of PHPMailer - upgrade to 6.0.