I am trying sending email using PHPMailer without TLS, but PHPMailer still tries to send email with TLS even if I do not enable it:
include_once("PHPMailer-master\PHPMailerAutoload.php");
$To = 'some#site.com';
$Subject = 'Topic';
$Message = 'msg test';
$Host = 'site.com.br';
$Username = 'contact#site.com.br';
$Password = 'pass';
$Port = "587";
$mail = new PHPMailer();
$body = $Message;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = $Host; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
//$mail->SMTPSecure = 'ssl'; //or tsl -> switched off
$mail->Port = $Port; // set the SMTP port for the service server
$mail->Username = $Username; // account username
$mail->Password = $Password; // account password
$mail->SetFrom($Username);
$mail->Subject = $Subject;
$mail->MsgHTML($Message);
$mail->AddAddress($To);
if(!$mail->Send()) {
$mensagemRetorno = 'Error: '. print($mail->ErrorInfo);
echo $mensagemRetorno;
} else {
$mensagemRetorno = 'E-mail sent!';
echo $mensagemRetorno;
}
After send email, I got this message:
2016-09-01 21:08:55 CLIENT -> SERVER: EHLO www.johnmendes.com.br
2016-09-01 21:08:55 CLIENT -> SERVER: STARTTLS
2016-09-01 21:08:55 SMTP ERROR: STARTTLS command failed: 454 TLS not available due to temporary reason
2016-09-01 21:08:55 SMTP Error: Could not connect to SMTP host.
2016-09-01 21:08:55 CLIENT -> SERVER: QUIT
2016-09-01 21:08:55 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Erro ao enviar e-mail: 1
The server doesn't support ssl or tls.
Any idea?
This is covered in the PHPMailer docs. PHPMailer does opportunistic TLS - if the server advertises that it can do TLS (which yours does), it will use it automatically without you asking. You can disable this:
$mail->SMTPSecure = false;
$mail->SMTPAutoTLS = false;
From the error message, it looks like this is a temporary problem on your hosting provider. You would see more info if you set $mail->SMTPDebug = 2;.
I can see you've based your code on an obsolete example, so make sure you have the latest version of PHPMailer and base your code on the examples supplied with it.
I had the same problem using one.com: SMTP 465 wasn't working.
I could using port 25 with this configuration in phpmailer:
$mail->Host = 'send.one.com';
$mail->SMTPAuth = true;
$mail->Username = "***";
$mail->Password = "******";
$mail->From = "***";
$mail->SMTPAutoTLS = false;
$mail->SMTPSecure = 'none';
$mail->Port = 25;
Related
I want to send mail using phpmailer. I have uploaded my phpmailer files on my Godaddy server. The below code is running in my localhost but not on my server.
2019-02-03 16:54:12 SMTP ERROR: Failed to connect to server: Connection refused (111)
The below is the code for php
<?php
include_once('PHPMailer/src/PHPMailer.php');
include_once('PHPMailer/src/SMTP.php');
$mail = new PHPMailer\PHPMailer\PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587,465
$mail->IsHTML(true);
$mail->Username = "mail#gmail.com";
$mail->Password = "password";
$mail->SetFrom("mail#gmail.com");
$mail->Subject = "Test mail";
$mail->Body = "Hello World";
$mail->AddAddress("mail#gmail.com");
if($mail->Send()) {
echo "Message has been sent";
}
?>
use PHPMailer\PHPMailer\PHPMailer; <-- make sure these are not in a function
use PHPMailer\PHPMailer\Exception;
require 'path/src/Exception.php';
require 'path/src/PHPMailer.php';
require 'path/src/SMTP.php';
Use tls and not ssl it can be buggy
$mail->SMTPSecure = "tls";
$mail->Port = 587;
Check out my answer here this will tell you everything you need to know to connect to gmail with phpmailer
I am trying to send an e-mail using this PHP code:
require("PHPMailer-master/src/PHPMailer.php");
require("PHPMailer-master/src/SMTP.php");
require("PHPMailer-master/src/Exception.php");
$from = "admin#mydomain.com";
$namefrom = "admin";
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->isSMTP(); // by SMTP
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true; // user and password
$mail->Host = "mail.gandi.net";
$mail->Port = 110;
$mail->Username = $from;
$mail->Password = "Password123";
$mail->CharSet = 'UTF-8';
// $mail->SMTPSecure = ""; // options: 'ssl', 'tls' , ''
$mail->setFrom($from,$namefrom); // From (origin)
$mail->addCC($from,$namefrom); // There is also addBCC
$mail->Subject = "Some subject";
$mail->AltBody = "Altenrate";
$mail->Body = "Heyheyhey";
$mail->isHTML(false); // Set HTML type
$mail->addAddress("hello#hotmail.com", "hello#hotmail.com");
if($mail->send())
{
echo "ok sent";
}
else
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
Thing is when using this code, it takes ages to load and ends up showing this error to me:
2018-12-09 20:50:24 CLIENT -> SERVER: EHLO www.mydomain.be
2018-12-09 20:53:24 SMTP ERROR: EHLO command failed: -ERR Unknown command.-ERR Disconnected for inactivity.
2018-12-09 20:53:24 SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not authenticate.
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Could someone explain me what the issue is and how to solve it?
Thanks!
you have the wrong settings according to :https://docs.gandi.net/en/gandimail/standard_email_settings/index.html
it should be
Outgoing (SMTP) server name: mail.gandi.net
Port: 25, 465 (with SSL) or 587 (with STARTTLS)
TLS or SSL: yes
SMTP Authentication: yes, using the same settings as for the POP / IMAP account
Hello traducerad,
$mail->isSMTP(); // by SMTP
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true; // user and password
$mail->Host = "mail.gandi.net";
$mail->Port = 110;
$mail->Username = $from;
$mail->Password = "Password123";
// $mail->SMTPSecure = "";
Port 110 is for incoming POP communication.
I think you want to send an email via SMTP.
Outgoing (SMTP) server name: mail.gandi.net
Port: 25, 465 (with SSL) or 587 (with STARTTLS)
TLS or SSL: yes
SMTP Authentication: yes, using the same settings as for the POP / IMAP account
FAQ from gandi.net
I want to send an email without SSL using PHPMailer. I have enabled the debug mode so that I can check the details in the logs.
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP(true); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = false; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "mail.company.co.uk";
$mail->Port = 25; // or 587
$mail->IsHTML(true);
$mail->Username = "email#company.co.uk";
$mail->Password = "password_of_username";
$mail->SetFrom($email,$name);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AddAddress($to);
This is giving an exception:
2018-09-28 10:04:27 CLIENT -> SERVER: EHLO localhost<br>
2018-09-28 10:04:27 CLIENT -> SERVER: STARTTLS<br>
SMTP Error: Could not connect to SMTP host.<br>
2018-09-28 10:04:28 CLIENT -> SERVER: QUIT<br>
2018-09-28 10:04:28 <br>
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting<br>
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
You've based your code on an old example, which doesn't help. You can't see what's going on because you've only used 1 for SMTPDebug; set it to 2.
Your mail server is advertising that it supports STARTTLS on port 25, so PHPMailer is using it automatically. You can disable encryption entirely by doing this:
$mail->SMTPAutoTLS = false;
$mail->SMTPSecure = false;
However, I'd recommend not doing this; fix your TLS config instead. You probably need to update your local CA certificate bundle - see the troubleshooting guide for more details.
You can try this: $mail->SMTPAuth = false;
I am really hoping one of you can help me. I've been pulling my hair out for about 2 hours with this. One of the accounts on my client's email servers got compromised and Google start blocking attempts for us to send emails. So I am trying to switch from the basic PHP mail command to PHPMailer and send through Google's SMTP server. This client uses Google Pro for all of his accounts.
I am using the following:
$mail = new PHPMailer();
$mail->isSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->SMTPSecure = "tls"; // sets the prefix to the server
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "no-reply#mydomain.com"; // GMAIL username
$mail->Password = "*********"; // GMAIL password
$mail->SetFrom('no-reply#mydomain.com', 'Jimmy');
$mail->Subject = $this->subject;
$body = $this->message;
//$body = eregi_replace("[\]",'',$body);
$mail->MsgHTML($body);
$mail->AddAddress($this->to, 'bob');
if(!$mail->Send()) {
error_log("Mailer Error: " . $mail->ErrorInfo);
echo '[br /]Fail';
} else {
error_log("Message sent!");
echo '[br /]Pass';
}
I know the credentials are correct because I can login with them. I've done all kinds of stuff to this script and the account it is trying to use to send:
Change from TLS to SSL
'unblock captcha' in the account
disabled 2 factor auth (it was already off)
enabled 'less secure apps'
I'm not sure what else to do. This is the error I keep getting:
2017-05-15 03:12:30 CLIENT -> SERVER: EHLO americanbeautytools.com
2017-05-15 03:12:30 CLIENT -> SERVER: STARTTLS
2017-05-15 03:12:30 CLIENT -> SERVER: EHLO americanbeautytools.com
2017-05-15 03:12:30 CLIENT -> SERVER: AUTH LOGIN
2017-05-15 03:12:30 CLIENT -> SERVER: xxx=
2017-05-15 03:12:30 CLIENT -> SERVER: xxx=
2017-05-15 03:12:32 SMTP ERROR: Password command failed: 535 Incorrect authentication data
2017-05-15 03:12:32 SMTP Error: Could not authenticate.
2017-05-15 03:12:32 CLIENT -> SERVER: QUIT
2017-05-15 03:12:32 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
The part about password command failed is the part I don't get. How can that be wrong when I login with that email account just fine?
I have looked at about 15 of the threads on this topic and none of what they suggest solves my problem. This is a google pro account that my client runs through google so it wouldn't be the 'free' restriction thing.
Test with G-suite account or sendgrid account. I have tested with my gmail credentials it works.
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = 'admin#gmail.com'; // SMTP username
$mail->Password = '123456789'; // SMTP password
$mail->setFrom('admin#gmail.com, 'Krishna');
$mail->addAddress($to_addr, 'Test'); // Add a recipient
$mail->Subject = $subject;
$mail->isHTML(true);
$mail->Body = $message;
Try making a new Gmail account for the sole purpose of this project. I was facing the exact problem, apparently, Google doesn't let the server login to your account from some location very far away.
Creating a new account worked fine for me, hope it helps.
<?php
require ('../PHPMailerAutoload.php'); //add PhPMailerAutoload.php file Path
$mail = new PHPMailer(); // create Object
$name=$_POST['Name']; //get name from post method
$to=$_POST['email']; //get email from post method
$message = $_POST['message']; //get msg from post method
$mail->isSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->SMTPSecure = "ssl"; // sets the prefix to the server
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "no-reply#mydomain.com"; // GMAIL username
$mail->Password = "*********"; // GMAIL password
$mail->SetFrom('no-reply#mydomain.com', 'Jimmy'); //Set who the message is to be sent from
$mail->Subject = "Email from Mailer"; // $this->subject;
$mail->Body = "test Email msg"; // $this->message;
$mail->isHTML(true);
$mail->MsgHTML($message);
$mail->addAddress($to,$name);
$mail->WordWrap = 70;
if(!$mail->Send()) {
echo 'Message could not be sent.'.'<br>';
echo "Mailer Error: " . $mail->ErrorInfo);
exit;
} else {
echo 'Message sent.'.'<br>';
exit;
}
?>
I'm trying to get PHPMailer working using a Google Apps SMTP server. I've tried:
Uncommenting openssl in php.ini
Telneting Google's server on port 465 (success)
Telneting my webserver on port 465 (success)
Telnetting Google's server from my server (success)
Checking DNS SPF/MX records (and sanitizing to IPv4)
tls on port 587
webhost confirms they allow outbound SMTP traffic
google captcha's unlock trick
Reading everything I could find on StackOverflow (solutions covered the above)
Can someone provide a solution to the timed out connection?
Here's my code:
require_once ( 'class.phpmailer.php' ); // Add the path as appropriate
$Mail = new PHPMailer();
$Mail->IsSMTP(); // Use SMTP
$Mail->Host = "smtp.gmail.com"; // Sets SMTP server
$Mail->SMTPDebug = 1; // 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE; // enable SMTP authentication
$Mail->SMTPSecure = "ssl"; //Secure conection
$Mail->Port = 465; // set the SMTP port
$Mail->Username = 'account#googleappsaddress.com'; // SMTP account username
$Mail->Password = 'mypassword'; // SMTP account password
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'Test Email Using Gmail';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = 'myemail#gmail.com';
$Mail->FromName = 'GMail Test';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$Mail->AddAddress( $to ); // To:
$Mail->isHTML( TRUE );
$Mail->Body = $body;
$Mail->AltBody = $MessageTEXT;
$Mail->Send();
$Mail->SmtpClose();
if(!$Mail->Send()) {
$error = 'Mail error: '.$Mail->ErrorInfo;
echo($error);
return false;
} else {
$error = 'Message sent!';
return true;
}
It turns out I was a victim of coincidence. When I ssh'ed to my server and telneted to Gmail, it was open - however, due to the openssl not being uncommented, I suspect that is why it initially failed.
However, while attempting to get it working, the host firewall blacklisted Gmail. They're currently looking into why, but the short answer is it is white-listed and working.