1

My issue:

Using PHPMailer I can't send authenticated SMTP emails when using the localhost Host. I can't see why this is so.

I realise the core root of the problem here is almost certainly a setting on Exim, rather than PHPMailer, but I can't find any working solution for resolving this.

About my server:

I have my own server which has Exim 4.87 set up and PHPMailer 5.2.16 . The server has about 100 accounts on it, many with their own mailing lists, etc.

The server runs the account DNS, SMTP and hosting all on the same place, so PHP scripts calling the Exim mailer don't need to leave the server, it's all local.

Attempts to fix:

Similar symptoms to this issue. Following reading this post I have relaxed Exim settings to allow emails by nobody (PHP) and various other allowances in Exim:

  • Allow email send from Nobody = ON
  • Trust X-PHP-Script headers to determine the sender of email sent from processes running as nobody = ON
  • Require remote (hostname/IP address) HELO = OFF
  • Require incoming SMTP connections to send a HELO that does not match this server’s local domains. = OFF

And yes I have read the PHPMailer documentation regarding unsent/failed emails.

My PHPMailer setup (only the important relevant bits):

    //$this->Host = "server-hostname.co.uk";     //THis WORKS
    //$this->Host = "account-domain.co.uk"; // this WORKS
    $this->Host = "localhost";  // this FAILS 
    $this->SMTPAuth = true; // Only works on non-localhost Host. 
    //$this->Port = 25; //default. 
    $this->Username = 'email_Address@accountdomain.co.uk';
    $this->Password = '...!...';

I can verify that the correct port for TLS is 487 and the correct port for plain SMTP is 25. The username and password are correct. The details above work when the host is NOT Localhost . But localhost doesn't accept any sending authentication.

My issue is that for email verification purposes (and good practise) I need to authenticate the outgoing emails, but I can only authenticate them if the Host is a remote host rather than the localhost.

This to me causes a 2 second delay which I would like to remove. I realise the delay comes from both the Authentication as well as from SMTPSecure. This answer gives me pointers about using localhost to mitigate this delay, and that makes perfect sense to me but somehow the Server setup is not accepting this.

I have a standard PHPMailer setup using Host->localhost and it works fine except it does not use SMTP Authentication or SMTPSecurity.

ERRORS:

(SMTPDebug = 4)
Note: Apologies the domain names are inconsistent (.com and .co.uk) but you get the idea...

2016-11-24 14:40:52 Connection: opening to localhost:25, timeout=20, options=array (
                                      )
2016-11-24 14:40:52 Connection: opened
2016-11-24 14:40:52 SMTP -> get_lines(): $data is ""
2016-11-24 14:40:52 SMTP -> get_lines(): $str is  "220-serverdomain.com ESMTP Exim 4.87  #1 Thu, 24 Nov 2016 14:40:52 +0000 
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "220-serverdomain.com ESMTP Exim 4.87  #1 Thu, 24 Nov 2016 14:40:52 +0000 
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $str is  "220-   We do not authorize the use of this system to transport unsolicited, 
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "220-serverdomain.com ESMTP Exim 4.87  #1 Thu, 24 Nov 2016 14:40:52 +0000 
                                      220-   We do not authorize the use of this system to transport unsolicited, 
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $str is  "220    and/or bulk e-mail.
                                      "
2016-11-24 14:40:52 SERVER -> CLIENT: 220-serverdomain.com ESMTP Exim 4.87  #1 Thu, 24 Nov 2016 14:40:52 +0000 
                                      220-   We do not authorize the use of this system to transport unsolicited, 
                                      220    and/or bulk e-mail.
2016-11-24 14:40:52 CLIENT -> SERVER: EHLO www.accountdomain.co.uk
2016-11-24 14:40:52 SMTP -> get_lines(): $data is ""
2016-11-24 14:40:52 SMTP -> get_lines(): $str is  "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $str is  "250-SIZE 52428800
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
                                      250-SIZE 52428800
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $str is  "250-8BITMIME
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
                                      250-SIZE 52428800
                                      250-8BITMIME
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $str is  "250-PIPELINING
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
                                      250-SIZE 52428800
                                      250-8BITMIME
                                      250-PIPELINING
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $str is  "250-AUTH PLAIN LOGIN
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
                                      250-SIZE 52428800
                                      250-8BITMIME
                                      250-PIPELINING
                                      250-AUTH PLAIN LOGIN
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $str is  "250-STARTTLS
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
                                      250-SIZE 52428800
                                      250-8BITMIME
                                      250-PIPELINING
                                      250-AUTH PLAIN LOGIN
                                      250-STARTTLS
                                      "
2016-11-24 14:40:52 SMTP -> get_lines(): $str is  "250 HELP
                                      "
2016-11-24 14:40:52 SERVER -> CLIENT: 250-serverdomain.com Hello www.accountdomain.co.uk [::1]
                                      250-SIZE 52428800
                                      250-8BITMIME
                                      250-PIPELINING
                                      250-AUTH PLAIN LOGIN
                                      250-STARTTLS
                                      250 HELP
2016-11-24 14:40:52 CLIENT -> SERVER: STARTTLS
2016-11-24 14:40:52 SMTP -> get_lines(): $data is ""
2016-11-24 14:40:52 SMTP -> get_lines(): $str is  "220 TLS go ahead
                                      "
2016-11-24 14:40:52 SERVER -> CLIENT: 220 TLS go ahead
2016-11-24 14:40:52 SMTP Error: Could not connect to SMTP host.
2016-11-24 14:40:52 CLIENT -> SERVER: QUIT
2016-11-24 14:40:52 SMTP -> get_lines(): $data is ""
2016-11-24 14:40:52 SMTP -> get_lines(): $str is  "221 serverdomain.com closing connection
                                      "
2016-11-24 14:40:52 SERVER -> CLIENT: 221 serverdomain.com closing connection
2016-11-24 14:40:52 Connection: closed
2016-11-24 14:40:52 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

What should I change on Exim (or elsewhere) so that SMTP Authentication can work on localhost ?

If needs be I can show you the Debug log from successful sendings when Host->"serverdomain.co.uk"; or Host->"accountdomain.co.uk"; . Cheers

EDIT:

OpenSSL is enabled on the PHP.

EDIT 2

Exim conf file Authentication (part of)

#BEGIN ACL_NOTQUIT_BLOCK
# BEGIN INSERT ratelimit

# ignore authenticated hosts
 accept authenticated = *

accept hosts = : +recent_authed_mail_ips : +loopback

warn
    #only rate limit port 25
    condition = ${if eq {$received_port}{25}{yes}{no}}
    condition = ${if match {$smtp_notquit_reason}{command}{yes}{no}}
    log_message = "Connection Ratelimit - $sender_fullhost because of notquit: $smtp_notquit_reason ($sender_rate/$sender_rate_period max:$sender_rate_limit)"
    ratelimit = 1.2 / 1h / strict / per_conn


# END INSERT ratelimit

#END ACL_NOTQUIT_BLOCK
  • Can you show authentication section of exim configuration file? – Mikhail Khirgiy Nov 24 '16 at 15:43
  • @MikhailKhirgiy I have the exim conf file but it's 70Kb in size and there's no clear authentication section so I can post up some of it but you'll have to give me a hint which parts I'm looking for? – Martin Nov 24 '16 at 15:49
  • Where's the line accept authenticated – Mikhail Khirgiy Nov 24 '16 at 16:05
  • @MikhailKhirgiy got it, question updated. Cheers – Martin Nov 24 '16 at 17:14
  • You can send messages without authentication via loopback interface and SMTP port 25. – Mikhail Khirgiy Nov 24 '16 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.