Hello,
I am experiencing the problem that I tried to get a PHP Mailer work.
This is the error I get:
2022-03-07 16:16:11 SERVER -> CLIENT: 220 mail.MYDOMAIN.de ESMTP Postcow
2022-03-07 16:16:11 CLIENT -> SERVER: EHLO ServerIPAddress
2022-03-07 16:16:11 SERVER -> CLIENT: 250-mail.MYDOMAIN.de250-PIPELINING250-SIZE 104857600250-ETRN250-STARTTLS250-ENHANCEDSTATUSCODES250-8BITMIME250-DSN250 CHUNKING
2022-03-07 16:16:11 CLIENT -> SERVER: STARTTLS
2022-03-07 16:16:11 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
2022-03-07 16:16:11 CLIENT -> SERVER: QUIT
2022-03-07 16:16:11
2022-03-07 16:16:11
SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
Bauhu
unknwn_usr
It looks like you’ve got a problem with your SSL configuration in your PHP.
Try the code below, if that doesn’t work you’ve got an issue with your certs
$mail = new PHPMailer(true);
try {
//$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = $mailhost; //MAIL SERVER
$mail->SMTPAuth = true; //REQUIRES AUTH
$mail->Username = $mailuser; //USERNAME
$mail->Password = $mailpass; //PASSWORD
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //USE SSL
$mail->Port = 587; //SSL PORT
$mail->addReplyTo($replyemail, $replyname); //REPLY TO SET TO EMAIL FROM FORM
$mail->setFrom($mailuser, $fromname); //FROM EMAIL
$mail->addAddress($to); //SET RECIPIENT
$mail->Subject = $subject; //SET MESSAGE SUBJECT
$mail->Body = $data;
if($file_name!=""){
$mail->addAttachment($basedir.$file_name,'Analytics.png');
$mail->send();
return true;
catch (Exception $e) {
return false;
$mail->SMTPSecure = false;
$mail->SMTPAutoTLS = false;
$mail->Username = “admin@MyDOMAINde”;
$mail->Password = “myPASSWORD”;
$mail->Port = 25;
Somehow it does work, but only to temp-mails. It get’s blocked in Gmail and Outlook.
Probably because I need the SMTP. While trying to get it working again, an error occurs.
Could this be a problem with Cloudflare SSL/TLS?
unknwn_usr
Looking at your code I’m assuming you’ve got Mailcow on the same machine as your webserver. Your using localhost as the hostname, thus the SSL cert wouldn’t match.
If your not using Cloudflare as a proxy you should be able to use your FQDN as the mail host.
Thanks for your reply! 🙂 I appreciate your help.
I do have these DNS in my Cloudflare account:
A - myDomain.de - IPv4 - Proxied
A - mail - IPv4 - DNS only
CNAME - autoconfig - mail.myDomain.de - DNS only
CNAME - autodiscover - mail.myDomain.de - DNS only
CNAME - www - myDomain.de - Proxied
MX - myDomain.de - mail.myDomain.de - Priority 10 - DNS only
TXT - myDomain.de - “v=spf1 mx a -all” - DNS only
TXT - dkim._domainkey - domain key from mailcow UI
TXT - _dmarc = “v=DMARC1; p=reject; rua=mailto:
[email protected]
”
Cloudflare SSL/TLS is currently turned off. When I change it to “Full”, what do I have to change in the php script, to get Mailcow working with the PHP?
$mail->Host = “mail.myDomain.de”;
// $mail->SMTPAuth = true;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //USE SSL
$mail->Port = 587; //SSL PORT
Bauhu
root@dedicated-1:~# ping -c 10 mail.myDomain.de
PING mail.myDomain.de (myIPv4) 56(84) bytes of data.
64 bytes from myIPv4 (myIPv4): icmp_seq=1 ttl=64 time=0.043 ms
64 bytes from myIPv4 (myIPv4): icmp_seq=2 ttl=64 time=0.067 ms
64 bytes from myIPv4 (myIPv4): icmp_seq=3 ttl=64 time=0.053 ms
64 bytes from myIPv4 (myIPv4): icmp_seq=4 ttl=64 time=0.060 ms
64 bytes from myIPv4 (myIPv4): icmp_seq=5 ttl=64 time=0.063 ms
64 bytes from myIPv4 (myIPv4): icmp_seq=6 ttl=64 time=0.055 ms
64 bytes from myIPv4 (myIPv4): icmp_seq=7 ttl=64 time=0.067 ms
64 bytes from myIPv4 (myIPv4): icmp_seq=8 ttl=64 time=0.057 ms
64 bytes from myIPv4 (myIPv4): icmp_seq=9 ttl=64 time=0.058 ms
64 bytes from myIPv4 (myIPv4): icmp_seq=10 ttl=64 time=0.058 ms
— mail.myDomain.de ping statistics —
10 packets transmitted, 10 received, 0% packet loss, time 222ms
Invalid host: 0de”
SMTP Error: Could not connect to SMTP host.
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.
My index.php:
$p = $_GET;
if($p[‘pass’] != “sitePass”) {
die(‘message’);
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//Load Composer’s autoloader
require ‘vendor/autoload.php’;
//Create an instance; passing
true
enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->IsSMTP();
$mail->Host = “mail.myDomain.de”;
// $mail->SMTPAuth = true;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //USE SSL
$mail->Port = 587; //SSL PORT
$mail->SMTPDebug = SMTP:😃EBUG_SERVER;
//Recipients
// $mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('[email protected]'); //Add a recipient
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo “Message could not be sent. Mailer Error: {$mail->ErrorInfo}”;
2022-03-08 15:07:32 SERVER -> CLIENT: 220 mail.myDomain.de ESMTP Postcow
2022-03-08 15:07:32 CLIENT -> SERVER: EHLO myIPv4
2022-03-08 15:07:32 SERVER -> CLIENT: 250-mail.myDomain.de250-PIPELINING250-SIZE 104857600250-ETRN250-STARTTLS250-ENHANCEDSTATUSCODES250-8BITMIME250-DSN250 CHUNKING
2022-03-08 15:07:32 CLIENT -> SERVER: STARTTLS
2022-03-08 15:07:32 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
2022-03-08 15:07:32 CLIENT -> SERVER: QUIT
2022-03-08 15:07:32
2022-03-08 15:07:32
SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
SSL/TLS is enabled in Cloudflare.