Whenever i try to send an E-mail (outlook SMTP) using: Phpmailer i get this error:
2020-06-05 18:45:05 Connection: opening to smtp.office365.com:587, timeout=300, options=array()
2020-06-05 18:45:05 Connection: opened
2020-06-05 18:45:05 SERVER -> CLIENT: 220 AM0PR10CA0059.outlook.office365.com Microsoft ESMTP MAIL Service ready at Fri, 5 Jun 2020 18:45:05 +0000
2020-06-05 18:45:05 SERVER -> CLIENT: 250-AM0PR10CA0059.outlook.office365.com Hello [82.165.86.40]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2020-06-05 18:45:05 CLIENT -> SERVER: STARTTLS
2020-06-05 18:45:05 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2020-06-05 18:45:05 SERVER -> CLIENT: 250-AM0PR10CA0059.outlook.office365.com Hello [82.165.86.40]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-AUTH LOGIN XOAUTH2250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2020-06-05 18:45:05 CLIENT -> SERVER: AUTH LOGIN
2020-06-05 18:45:05 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2020-06-05 18:45:05 CLIENT -> SERVER: [credentials hidden]
2020-06-05 18:45:05 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2020-06-05 18:45:05 CLIENT -> SERVER: [credentials hidden]
2020-06-05 18:45:10 SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful [AM0PR10CA0059.EURPRD10.PROD.OUTLOOK.COM]
2020-06-05 18:45:10 SMTP ERROR: Password command failed: 535 5.7.3 Authentication unsuccessful [AM0PR10CA0059.EURPRD10.PROD.OUTLOOK.COM]
SMTP Error: Could not authenticate.
2020-06-05 18:45:10 CLIENT -> SERVER: QUIT
2020-06-05 18:45:10 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
2020-06-05 18:45:10 Connection: closed
SMTP Error: Could not authenticate.
I tried with Codeigniter as well
Failed to authenticate password. Error:
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
i tried both way but not working ...
i am using codeigniter default mail class
here is the config:
$config = array(
'smtp_crypto' => 'tls', or 'startTls'
'smtp_auth' => true,
'protocol' => 'smtp',
'smtp_host' => 'smtp.office365.com',
'smtp_port' => 587,
'smtp_timeout' => '7',
'smtp_user' => 'email#account.com',
'smtp_pass' => 'emailPassword', or 'APPPASSWORD'
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE,
'validation' => TRUE
);
This is the Phpmailer Config:
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->SMTPAuth = false;
$mail->Username = 'email#account.com';
$mail->Password = 'emailPassword'; or 'APPPASSWORD'
$mail->SMTPSecure = 'tls', or 'startTls',
$mail->Port = 587
anybody faced with type of problem ?
Looking for some help !!!
I had some certificate issues and thats how I used it finally:
<?php
$mailusername= "******";
$mailpassword= "******";
$mailhost= "smtp.office365.com";
$to="*******";
$subject="test";
$body="abcdef";
require_once('PHPMailer-master/class.phpmailer.php');
require_once('PHPMailer-master/class.smtp.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->Host = $mailhost;
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Username = $mailusername;
$mail->Password = $mailpassword;
$frommail = $mailusername;//$this->from;
$fromname = "Mailbot";
$mail->SetFrom($frommail, $fromname);
$address = $to;
$adrname = "";
$mail->AddAddress($address, $adrname);
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->Send()) {
//echo "Mailer Error: " . $mail->ErrorInfo;
print( "sendViaSMTP() - failed to send email");
} else {
print( "sendViaSMTP() - success sending email");
// all good
}
?>
(1) For me the tricky part were the SMTPOptions().
(2) The other tricky part was to use the latest PHPMailer() lib. Because the SMTPOptions() is only supported by newer PHPMailer()
(3) Using the "no-verify" option is insecure. However on some servers needed due to setup / configuration issues.
updated my code
I am using PHPMailer
public $Version = '5.2.8';
I'm trying to send an e-mail with PHPMailer to my SMTP server hosted with Mail-In-A-Box (which uses Postfix) on another Ubuntu 16.04 VPS, but I have an error
The mail vps is hosted on Digital Ocean, same for the website/php one
This is what I get when I run the code:
2019-02-26 17:54:01 CLIENT -> SERVER: EHLO mail
2019-02-26 17:54:01 SERVER -> CLIENT: 250-mail.ultracore.it
250-PIPELINING
250-SIZE 134217728
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250 SMTPUTF8
2019-02-26 17:54:01 CLIENT -> SERVER: STARTTLS
2019-02-26 17:54:01 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2019-02-26 17:54:01 SMTP Error: Could not connect to SMTP host.
2019-02-26 17:54:01 CLIENT -> SERVER: QUIT
2019-02-26 17:54:01 SERVER -> CLIENT:
2019-02-26 17:54:01 SMTP ERROR: QUIT command failed:
2019-02-26 17:54:01 SMTP Error: Could not connect to SMTP host.
This is the code I use to send the email:
function sendEmail($from, $password, $email, $subject, $messageHtml, $message)
{
$mail = new PHPMailer(true);
//$pop = POP3::popBeforeSmtp('pop3.ultracore.it', 110, 1, $from, $password, 2);
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.ultracore.it'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $from; // SMTP username
$mail->Password = $password; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom($from, $from);
$mail->addAddress($email, 'Joe User'); // Add a recipient
$mail->addReplyTo('support#ultracore.it', 'Support');
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $messageHtml;
$mail->AltBody = $message;
$mail->send();
echo 'The message has been sent';
} catch (Exception $e) {
echo $mail->ErrorInfo;
}
}
It's the PHPMailer's example modified.
As you can see I tried using the popBeforeSMTP function, but I had the same error, and another one before it:
<pre>Connecting to the POP3 server raised a PHP warning:errno: 2 errstr: fsockopen(): unable to connect to pop3.ultracore.it:110 (Connection refused); errfile: /var/www/html/vendor/phpmailer/phpmailer/src/POP3.php; errline: 238</pre><pre>Connecting to the POP3 server raised a PHP warning:errno: 2 errstr: fsockopen(): unable to connect to pop3.ultracore.it:110 (Connection refused); errfile: /var/www/html/vendor/phpmailer/phpmailer/src/POP3.php; errline: 238Failed to connect to server pop3.ultracore.it on port 110. errno: 111; errstr: Connection refused</pre>
I tried with ssl instead of tls, but I'm receiving this:
2019-02-26 18:03:52 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshootingr`
I know some other user have asked a question like this, but none of the solutions I've tried worked for me.
I've imported PHPMailer through the composer with this line
"require": {
"phpmailer/phpmailer": "~6.0"
}
Update
I changed the code to this (still coming from the PHPMailer examples)
function sendEmail($from, $password, $to, $subject, $messageHtml)
{
$smtp_settings = array(
"debug" => 2,
"host" => "smtp.ultracore.it",
"port" => 587,
"auth" => true,
"encryption" => "tls",
"reply_address" => "support#ultracore.it",
"peer_name" => "smtp.ultracore.it",
"verify_peer" => true,
"verify_depth" => 3,
"allow_self_signed" => false,
"cafile" => "/var/www/html/certificates/ssl_private_key.pem"
);
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = $smtp_settings['debug'];
//Set the hostname of the mail server
$mail->Host = $smtp_settings['host'];
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = $smtp_settings['port'];
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = $smtp_settings['encryption'];
//Custom connection options
//Note that these settings are INSECURE
$mail->SMTPOptions = array(
'ssl' => [
'verify_peer' => $smtp_settings['verify_peer'],
'verify_depth' => $smtp_settings['verify_depth'],
'allow_self_signed' => $smtp_settings['allow_self_signed'],
'peer_name' => $smtp_settings['peer_name'],
'cafile' => $smtp_settings['cafile'],
],
);
//Whether to use SMTP authentication
$mail->SMTPAuth = $smtp_settings['auth'];
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = $from;
//Password to use for SMTP authentication
$mail->Password = $password;
//Set who the message is to be sent from
$mail->setFrom($from, 'First Last');
//Set who the message is to be sent to
$mail->addAddress($to, 'John Doe');
//Set the subject line
$mail->Subject = $subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML($messageHtml, __DIR__);
//Send the message, check for errors
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent!';
}
}
But I have the same error
2019-02-26 21:48:23 SERVER -> CLIENT: 220 mail.ultracore.it ESMTP Hi, I'm a Mail-in-a-Box (Ubuntu/Postfix; see https://mailinabox.email/)
2019-02-26 21:48:23 CLIENT -> SERVER: EHLO ultracore.it
2019-02-26 21:48:23 SERVER -> CLIENT: 250-mail.ultracore.it250-PIPELINING250-SIZE 134217728250-VRFY250-ETRN250-STARTTLS250-ENHANCEDSTATUSCODES250-8BITMIME250-DSN250 SMTPUTF8
2019-02-26 21:48:23 CLIENT -> SERVER: STARTTLS
2019-02-26 21:48:23 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2019-02-26 21:48:23 CLIENT -> SERVER: QUIT
2019-02-26 21:48:23 SERVER -> CLIENT:
2019-02-26 21:48:23 SMTP ERROR: QUIT command failed:
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I tried switching the cafile to all of this files:
files I tried
Am I doing this wrong? The files are on the website's VPS, I've applied the certificates to the server through Mail-In-A-Box's admin panel.
I have CloudFlare, but the address smtp.ultracore.it is not under cloudflare's protection, and all the certificates are created on the Mail VPS' address, so ultracore.it is created with the address of mail.ultracore.it, not the website's one...
The code
echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."<br>";
returns this
SSL loaded
You're using SMTPSecure = 'ssl' (implicit TLS) on port 587, which expects explicit TLS (STARTTLS). This is covered in all the examples and the docs.
When STARTTLS fails, it's most likely due to an invalid certificate, or an invalid CA certificate, and again, that is covered in the troubleshooting guide.
Don't use POP-before-SMTP; that's a really ancient auth mechanism and should not be used.
I fixed setting "verify_peer" to false, so my code looks like this now:
function sendEmail($from, $password, $to, $subject, $messageHtml)
{
$smtp_settings = array(
"debug" => 2,
"host" => "mail.ultracore.it",
"port" => 587,
"auth" => true,
"encryption" => "tls",
"reply_address" => "support#ultracore.it",
"peer_name" => "mail.ultracore.it",
"verify_peer" => false,
"verify_depth" => 3,
"allow_self_signed" => true,
"cafile" => "/var/www/html/certificates/ssl_certificate.pem"
);
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = $smtp_settings['debug'];
//Set the hostname of the mail server
$mail->Host = $smtp_settings['host'];
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = $smtp_settings['port'];
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = $smtp_settings['encryption'];
//Custom connection options
//Note that these settings are INSECURE
$mail->SMTPOptions = array(
'ssl' => [
'verify_peer' => $smtp_settings['verify_peer'],
'verify_depth' => $smtp_settings['verify_depth'],
'allow_self_signed' => $smtp_settings['allow_self_signed'],
'peer_name' => $smtp_settings['peer_name'],
'cafile' => $smtp_settings['cafile'],
],
);
//Whether to use SMTP authentication
$mail->SMTPAuth = $smtp_settings['auth'];
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = $from;
//Password to use for SMTP authentication
$mail->Password = $password;
//Set who the message is to be sent from
$mail->setFrom($from, 'First Last');
//Set who the message is to be sent to
$mail->addAddress($to, 'John Doe');
//Set the subject line
$mail->Subject = $subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML($messageHtml, __DIR__);
//Send the message, check for errors
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent!';
}
}
I'm trying to setup PHP mailer on my VPS with Plesk SMTP.
The PHP code
require("path_to_phpmailer");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
try {
//Server settings
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->CharSet = 'UTF-8';
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->SMTPSecure = 'tls';
$mail->SMTPOptions = array (
'ssl' => array(
'verify_peer' => true,
'verify_depth' => 3,
'allow_self_signed' => true,
'peer_name' => 'Plesk',
)
);
$mail->SMTPAuth = true;
$mail->Username = 'support#mywebsite.com';
$mail->Password = 'somepassword';
$mail->setFrom('support#mywebsite.com', 'Name Surname');
$mail->addAddress('someadress#web.de', 'Name Surname');
$mail->Subject = 'Email subject';
$mail->msgHTML('Email content with <strong>html</strong>');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
support#mywebsite.com is the email that i created in my ples dashboard and somepassword is its password. However running the script gives the following output:
2018-04-14 09:27:10 SERVER -> CLIENT: 220 myserver.net ESMTP
Postfix (Ubuntu)
2018-04-14 09:27:10 CLIENT -> SERVER: EHLO mywebsite.com
2018-04-14 09:27:10 SERVER -> CLIENT: 250-myserver.net250-
PIPELINING250-SIZE 10240000250-ETRN250-STARTTLS250-AUTH DIGEST-MD5 CRAM-MD5
PLAIN LOGIN250-XFORWARD NAME ADDR PROTO HELO SOURCE PORT IDENT250-
ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2018-04-14 09:27:10 CLIENT -> SERVER: STARTTLS
2018-04-14 09:27:10 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2018-04-14 09:27:10 CLIENT -> SERVER: QUIT
2018-04-14 09:27:10 SERVER -> CLIENT:
2018-04-14 09:27:10 SMTP ERROR: QUIT command failed:
SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/TroubleshootingMessage has been
sent
Did I understand something wrong?
Thank you in advance!
Check if is a problem with ssl, and try again
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
if it still has an error
$mail->SMTPDebug = 3;
https://github.com/PHPMailer/PHPMailer/wiki/SMTP-Debugging
I'm having trouble to send mail using phpmailer. Error appear is,
2016-02-16 13:20:14 Connection: opening to 103.8.25.18:465,
timeout=300, options=array ( 'ssl' => array ( 'verify_peer' => false,
'verify_peer_name' => false, 'allow_self_signed' => true, ), )
2016-02-16 13:20:35 SMTP ERROR: Failed to connect to server: A
connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed
because connected host has failed to respond. (10060) 2016-02-16
13:20:35 SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message
could not be sent.Mailer Error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
If I test using direct from my localhost PC, it can send the mail but when I transfer the system to our office server, it won't send the mail. Below are the phpmailer codes;
require '../PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.mydomain.com'; // Specify main and backup SMTP servers
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myusername'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->AddAddress('kamran#ktmparking.com.my');
$mail->addReplyTo('info#ktmparking.com.my', 'HR-KTMBCP');
$mail->setFrom('info#ktmparking.com.my', 'HR-KTMBCP');
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Leave Application';
$mail->Body = 'example of message ';
$mail->AltBody = 'example of message';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent';
}
I'm using PHPMailer, which works fine on my server, but not on my localhost. The function I'm using to send is:
function sendEmail($mail, $toEmail, $toName, $subject, $message, $noHtmlMessage) {
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'christopherpickardco.netfirms.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'webmaster#christopherpickard.com'; // SMTP username
$mail->Password = 'myPassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('webmaster#christopherpickard.com', 'ChrisComposes.com'); //
$mail->addAddress($toEmail, $toName); // Add a recipient. Right now this goes to me, in the end it will go to Chris
$mail->addReplyTo('webmaster#christopherpickard.com', 'ChrisComposes.com');
$mail->Subject = "ChrisComposes.com: " . $subject;
$mail->Body = $message;
$mail->AltBody = $noHtmlMessage;
$mail->send();
}
This works fine on my server but on my localhost I get an error: Warning: stream_socket_enable_crypto(): Peer certificate CN=smtp.eigbox.net' did not match expected CN=christopherpickardco.netfirms.com' in /Users/ChristopherPickard/Web_Development/chriscomposes/includes/phpmailer/class.smtp.php on line 344
How can I fix this?
From docs:
The correct fix for this is to replace the invalid, misconfigured or
self-signed certificate with a good one. Failing that, you can allow
insecure connections via the SMTPOptions property introduced in
PHPMailer 5.2.10 (it's possible to do this by subclassing the SMTP
class in earlier versions), though this is not recommended:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
This works.