[PHPMailer] Unable to send mail

Use this forum if you have installed hMailServer and want to ask a question related to a production release of hMailServer. Before posting, please read the troubleshooting guide. A large part of all reported issues are already described in detail here.
Post Reply
NivekLR
New user
New user
Posts: 19
Joined: 2018-05-16 03:22

[PHPMailer] Unable to send mail

Post by NivekLR » 2019-02-09 00:19

Hello to all,

I have installed and configured hMailServer.
I have tried it by roundcube webmail with success for internal and external addresses.

I have configured a PHP script that use PHPMailer to sent mails but the mail never been sent.
The hMailServer Logs show :

Code: Select all

"DEBUG"	14328	"2019-02-08 23:00:54.242"	"TCP connection started for session 16"
"SMTPD"	14328	16	"2019-02-08 23:00:54.242"	"127.0.0.1"	"SENT: 220 mail.klr-services.ovh ESMTP"
"SMTPD"	5600	16	"2019-02-08 23:00:54.242"	"127.0.0.1"	"RECEIVED: EHLO www.klr-services.ovh"
"SMTPD"	5600	16	"2019-02-08 23:00:54.242"	"127.0.0.1"	"SENT: 250-mail.klr-services.ovh[nl]250-SIZE 20480000[nl]250-STARTTLS[nl]250-AUTH LOGIN[nl]250 HELP"
"SMTPD"	5644	16	"2019-02-08 23:00:54.242"	"127.0.0.1"	"RECEIVED: STARTTLS"
"SMTPD"	5644	16	"2019-02-08 23:00:54.242"	"127.0.0.1"	"SENT: 220 Ready to start TLS"
"DEBUG"	14328	"2019-02-08 23:00:54.242"	"Performing SSL/TLS handshake for session 16. Verify certificate: False"
"TCPIP"	5600	"2019-02-08 23:05:54.254"	"TCPConnection - TLS/SSL handshake failed. Session Id: 16, Remote IP: 127.0.0.1, Error code: 335544539, Message: short read"
"DEBUG"	5600	"2019-02-08 23:05:54.254"	"Ending session 16"
I noticed that the error is normal because I have stopped the page loading.

This is my hMailServer report :

Code: Select all

2019-02-08   Hmailserver: 5.6.7-B2427

DOMAINS

   "Domain1.com" - klxxxxxxxxxx.ovx               Enabled: True

SIGNATURE         LIMITS                       DKIM               ADVANCED
  Enabled: False   Max size:                0   Enabled: True    
                   Max message size:        0   Header:   Relaxed  Plus addressing: False
                   Max size of accounts:    0   Body:     Relaxed
                                                Algorithm: SHA256  Greylisting:     False
                                                Private key: d:\wampserver\cert-auth\ca\intermediate\private\dkim.Domain1.com.pkey.pem
                                                Selector:    dkim
-----------------------------------------------------------------------------------------------

IP RANGES

IP: 127.0.0.1 - 127.0.0.1     Priority: 30     Name: My computer

  Allow connections                         Other
     SMTP:   True                              Antispam :   True !! 'Spam tests' not enabled !!
     POP3:  False                              Antivirus:   True !! ANTIVIRUS NOT CONFIGURED !!
     IMAP:   True                              SSL/TLS:     True

  Allow Deliveries from                     Require Authentication from
     Local To Local       -  True              Local To Local       -  True
     Local To External    -  True              Local To External    -  True
     External To Local    -  True              External To Local    - False
     External To External -  True              External To External -  True


IP: 0.0.0.0 - 255.255.255.255     Priority: 10     Name: Internet

  Allow connections                         Other
     SMTP:   True                              Antispam :   True !! 'Spam tests' not enabled !!
     POP3:  False                              Antivirus:   True !! ANTIVIRUS NOT CONFIGURED !!
     IMAP:   True                              SSL/TLS:     True

  Allow Deliveries from                     Require Authentication from
     Local To Local       -  True              Local To Local       -  True
     Local To External    -  True              Local To External    -  True
     External To Local    -  True              External To Local    - False
     External To External -  True              External To External -  True


------------------------------------------------------
AUTOBANNED Local Addresses:
    No entries

-----------------------------------------------------------------------------------------------

AUTOBAN
  Autoban Enabled: True       Max invalid logon attempts:      3
                              Minutes Before Reset:           30  (0.50 hours, 0.02 days)
                              Minutes to Autoban:             60  (1.00 hours, 0.04 days)

No problems were found in the IP range configuration.
-----------------------------------------------------------------------------------------------

INCOMING RELAYS
   No entries
-----------------------------------------------------------------------------------------------

MIRRORING         Disabled
-----------------------------------------------------------------------------------------------

PROTOCOLS

SMTP
GENERAL             DELIVERY                  RFC COMPLIANCE            ADVANCED
No. Connections:  0  No Retries: 10 Mins: 60   Plain Text:        False  Bind: 192.168.1.30
                     Host: EXTERNAL.TLD        Empty sender:       True  Batch recipients:   100
Max Msg Size: 20480  Relay:-                   Incorrect endings:  True  Use STARTTLS:      True
                      EXTERNAL.TLD  (ok)       Disc. on invalid:  False  Delivered-To hdr: False
                     Port: 587                                           Loop limit:           5
                     Req Auth: True *User Entered*                       Recipient hosts:     15
                     Con. Sec.: StartTLS Required
  Routes:
     No routes defined.

POP3
  No. Connections: 0

IMAP
 GENERAL                   PUBLIC FOLDERS                    ADVANCED
  No. Connections:   0      Public folder name: #Public       IMAP sort:  True
                                                              IMAP Quota: True
                                                              IMAP Idle:  True
                                                              IMAP ACL:   True
                                                              Delim: "."
-----------------------------------------------------------------------------------------------

ANTISPAM

GENERAL                              SPAM TESTS              Score   SPAMASSASSIN
  Spam Mark:                  5       Use SPF:           False        Use Spamassassin:   False
  Add X-HmailServer-Spam:     True    Check HELO host:   False    
  Add X-HmailServer-Reason:   True    Check MX records:  False    
  Add X-HmailServer-Subject: False    Verify DKIM:       False    

  Spam delete threshold: 20         Maximum message size: 1024

DNSBL ENTRIES:
   No 'enabled' entries

SURBL ENTRIES:
   No 'enabled' entries

GREYLISTING:
  Greylisting:  False

WHITELISTING
   No entries
-----------------------------------------------------------------------------------------------

ANTIVIRUS:  No application configured.

  Block Attachments: False
-----------------------------------------------------------------------------------------------

SSL CERTIFICATES
   IMAP
       Certificate: D:\WAMPServer\ssl\ca\intermediate\certs\imap.Domain1.com.cert.pem
       Private key: D:\WAMPServer\ssl\ca\intermediate\private\imap.Domain1.com.pkey.pem
   POP
       Certificate: D:\WAMPServer\ssl\ca\intermediate\certs\pop.Domain1.com.cert.pem
       Private key: D:\WAMPServer\ssl\ca\intermediate\private\pop.Domain1.com.pkey.pem
   SMTP
       Certificate: D:\WAMPServer\ssl\ca\intermediate\certs\smtp.Domain1.com.cert.pem
       Private key: D:\WAMPServer\ssl\ca\intermediate\private\smtp.Domain1.com.pkey.pem
-----------------------------------------------------------------------------------------------

SSL/TLS
             SSL 3.0 :  False
             TLS 1.0 :   True
             TLS 1.1 :   True
             TLS 1.2 :   True                Verify Remote SSL/TLS Certs:  False
SslCipherList  :

ECDHE-RSA-AES128-GCM-SHA256     - ECDHE-ECDSA-AES128-GCM-SHA256   - ECDHE-RSA-AES256-GCM-SHA384     
ECDHE-ECDSA-AES256-GCM-SHA384   - DHE-RSA-AES128-GCM-SHA256       - DHE-DSS-AES128-GCM-SHA256       
kEDH+AESGCM                     - ECDHE-RSA-AES128-SHA256         - ECDHE-ECDSA-AES128-SHA256       
ECDHE-RSA-AES128-SHA            - ECDHE-ECDSA-AES128-SHA          - ECDHE-RSA-AES256-SHA384         
ECDHE-ECDSA-AES256-SHA384       - ECDHE-RSA-AES256-SHA            - ECDHE-ECDSA-AES256-SHA          
DHE-RSA-AES128-SHA256           - DHE-RSA-AES128-SHA              - DHE-DSS-AES128-SHA256           
DHE-RSA-AES256-SHA256           - DHE-DSS-AES256-SHA              - DHE-RSA-AES256-SHA              
AES128-GCM-SHA256               - AES256-GCM-SHA384               - ECDHE-RSA-RC4-SHA               
ECDHE-ECDSA-RC4-SHA             - AES128                          - AES256                          
RC4-SHA                         - HIGH                            - !aNULL                          
!eNULL                          - !EXPORT                         - !DES                            
!3DES                           - !MD5                            - !PSK;                           
-----------------------------------------------------------------------------------------------

TCPIP PORTS                                         Connection Sec
               0.0.0.0         / 25    / SMTP   -   None                
               0.0.0.0         / 587   / SMTP   -   StartTLS Required   Cert: SMTP
               0.0.0.0         / 993   / IMAP   -   StartTLS Required   Cert: IMAP
               0.0.0.0         / 995   / POP3   -   StartTLS Required   Cert: POP
-----------------------------------------------------------------------------------------------

LOGGING      Logging Enabled: True

  Paths:-
    Current:  D:\WAMPServer\logs\mail\hmailserver_2019-02-08.log
    Error:    D:\WAMPServer\logs\mail\ERROR_hmailserver_2019-02-08.log
    Event:    D:\WAMPServer\logs\mail\hmailserver_events.log - Not present
    Awstats:  D:\WAMPServer\logs\mail\hmailserver_awstats.log
                        APPLICATION -    True
                        SMTP        -    True
                        POP3        -    True
                        IMAP        -    True
                        TCPIP       -    True
                        DEBUG       -    True
                        AWSTATS     -      .
-----------------------------------------------------------------------------------------------

SYSTEM TESTS

Database type: MySQL

IPv6 support is available in operating system.

Backup directory D:\WAMPBackup\hMailServer is writable.

Relative message paths are stored in the database for all messages.

There are no error logs in the log directory.
-----------------------------------------------------------------------------------------------

HMAILSERVER.INI

[Directories]
Program folder:  D:\WAMPPlugins\hMailServer\
Database folder: 
Data folder:     D:\WAMPPlugins\hMailServer\Data
Log folder:      D:\WAMPServer\logs\mail
Temp folder:     D:\WAMPPlugins\hMailServer\Temp
Event folder:    D:\WAMPPlugins\hMailServer\Events

[Database]
Type=              MYSQL
Username=          klr-mail
PasswordEncryption=1
Port=              3309
Server=            database.Domain1.com
Internal=          0
-----------------------------------------------------------------------------------------------

Generated by HMSSettingsDiagnostics v1.95, Hmailserver Forum.

And this is my PHP code :

Code: Select all

<?php
	// Fichiers nécessaires à l'envoi du mail
	require 'phpmailer/PHPMailer.php';
	require 'phpmailer/Exception.php';
	require 'phpmailer/SMTP.php';
	
	use PHPMailer\PHPMailer\PHPMailer;
	
	// Création d'une nouvelle instance
	$mail = new PHPMailer(true);
	
	// Configuration du serveur de mesagerie
	$mail->isSMTP();
	$mail->Host = 'smtp.Domain1.com';
	$mail->SMTPAuth = true;
	$mail->Username = "noreply@Domain1.com";
	$mail->Password = "xxxxxxxxxxx";
	$mail->SMTPSecure = 'tls';
	$mail->Port = 587;
	
	// Configuration de la sécurité
	$mail->SMTPOptions = array(
		'ssl' => [
			'verify_peer' => true,
			'verify_depth' => 3,
			'allow_self_signed' => true,
			'cafile' => 'd:/wampserver/ssl/ca/intermediate/ca-chain.cert.pem',
		],
	);
	$mail->SMTPAutoTLS = false;
	
	// Configuration du débogage
	$mail->SMTPDebug = 2;
	$mail->Debugoutput = 'html';
	
	// Configuration de l'en-tête du mail
	$mail->isHTML(true);
	$mail->Subject = 'Confirmation de votre adresse de messagerie';
	$mail->setFrom('noreply@Domain1.com', 'No Reply');
	$mail->addAddress($Email);
	
	// Configuration du contenu du mail
	$mail->Body = $Body;
	$mail->AltBody = $AltBody;
	
	if (!$mail->send()) {
		echo "Mailer Error: " . $mail->ErrorInfo;
	}
?>
The PHPMailer is configured as roundcube so I don't understand why the script is blocked like this :(

Kind regards,

User avatar
Dravion
Senior user
Senior user
Posts: 1297
Joined: 2015-09-26 11:50
Location: Germany
Contact:

Re: [PHPMailer] Unable to send mail

Post by Dravion » 2019-02-09 00:29

In hMailAdmin enable logging, logout from hMailAdmin, stop the hMailServer Service,
go c:\Program Files (x86) \hMailServer\logs (or where you installed hMailServer) and delete
all files within the log Folder.

Start hMailAdmin and click connect, this will autostart the hMailServer service.

Try to send an Email with PHPMailer and take a look at your new hMailServer logfiles which
should contain the circumstances of your Problem.
64-Bit builds of hMailserver

hMailServer-5.6.+ (HCD) https://github.com/hMailServer-ComDevs/hmailserver
hMailServer-5.6.+ (LTS) https://github.com/Dravion/hMailServer/releases

User avatar
mattg
Moderator
Moderator
Posts: 19707
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: [PHPMailer] Unable to send mail

Post by mattg » 2019-02-09 02:10

That error is because your PHP system and your hmailserver can't agree on a protocol or a cipher, or that your self signed cert isn't trusted by your PHP system

Is OpenSSL loaded in PHP?

Other hints here >> https://github.com/PHPMailer/PHPMailer/ ... leshooting
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

NivekLR
New user
New user
Posts: 19
Joined: 2018-05-16 03:22

Re: [PHPMailer] Unable to send mail

Post by NivekLR » 2019-02-09 10:21

Thanks for your answers.

@Dravion - Resetting the Log file does not show more information...
@mattg - I have used the command :

Code: Select all

echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."\n";
And SSL loaded appears.

I have already followed the link you mentioned but nothing works...
How I check the cipher used by my PHP system ?

Kind regards,

User avatar
mattg
Moderator
Moderator
Posts: 19707
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: [PHPMailer] Unable to send mail

Post by mattg » 2019-02-10 02:13

Does anything else use port 587 on your hmailserver?

if not change it to no security, and change your php mailer to no security on the connection and confirm that it works.

My guess is that you have a self signed or otherwise untrusted certificate on your hMailserver, that your PHP system doesn't like.

A few ways around that, so depending on where you got the cert etc
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

NivekLR
New user
New user
Posts: 19
Joined: 2018-05-16 03:22

Re: [PHPMailer] Unable to send mail

Post by NivekLR » 2019-02-10 11:59

Thanks mattg, I finished to solve the issue by founding a mistake in the certificate path... I am boring myself 😋

Kind regards,

Post Reply