SMTP connect error using phpmailer - php

I am using this code to send emails using smtp:
require 'phpmailer/class.phpmailer.php';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->Host = "sr4.supercp.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "********";
$mail->Password = "********";
$mail->SetFrom("********");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("****#gmail.com");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
echo "<pre>";
echo print_r($mail);
}
else
{
echo "Message has been sent";
}
Getting this error:
2014-08-25 18:53:11 CLIENT -> SERVER: EHLO grabblaw.com
2014-08-25 18:53:11 SMTP ERROR: EHLO command failed:
2014-08-25 18:53:11 SMTP NOTICE: EOF caught while checking if connected SMTP connect() failed. Mailer Error: SMTP connect() failed.
I have spend entire day, but unable to make this work. Please help.
Please refer this url for more error detailed info: http://grabblaw.com/mail_template.php

Similar to this question SMTP error with PHPMailer EHLO not supported
Changing your port to 25 should work:
I tried to telnet:
telnet grabblaw.com 25 //works
telnet grabblaw.com 465 //hangs
telnet grabblaw.com 587 //no response

You're setting:
$mail->Port = 465; // or 587
but there's no accompanying:
$mail->SMTPSecure = 'ssl'; // or 'tls'
So you're trying to send unencrypted data to an encrypted connection, which will not work (it's one of the reasons that SMTP over SSL was deprecated 15 years ago). TLS on 587 is more resistant to this.
Switching to port 25 usually means you're giving up on encryption altogether, which isn't a good solution.

Related

SMTP ERROR: EHLO command failed: -ERR Unknown command

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

EOF caught while checking if connected phpmailer

require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'myhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myusername'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 1060; // TCP port to connect to
$mail->setFrom('test#gmail.com', 'test');
$mail->isHTML(true); // Set email format to HTML
$mail->addAddress('test#gmail.com'); // Add a recipient
for($i=0;$i<1;$i++){
$mail->Subject = "test bulk email ".$i;
$mail->Body = "this is email ".$i;
if(!$mail->Send())
{
$error_message = "Mailer Error: " . $mail->ErrorInfo;
}
}
echo $error_message;
When I run this code, I get this error:
Connection: opened 2018-03-05 09:24:25 SERVER -> CLIENT: 2018-03-05 09:24:25 SMTP NOTICE: EOF caught while checking if connected 2018-03-05 09:24:25 Connection: closed 2018-03-05 09:24:25 SMTP Error: Could not connect to SMTP host.
How do I fix this?
You're using an unusual port number for SMTP submission, so check you have the right one for your host. It would usually be 587 when using SMTPSecure = 'tls'.
You're setting a gmail from address while sending through another host; that will cause you to fail SPF checks and your messages will either be blocked or spam filtered.
If you want to send to a list, follow the mailing list example provided with PHPMailer - your code contains some mistakes that will probably result in duplicate messages.

PHPMailer sends with TLS even when encryption is not enabled

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;

phpMailer send a smtp email

I am trying to send an email using phpMailer.
I have downloaded and put the files in "path2".
The php program has 3 inputs: $email, $subject and $body.
Here is the error code when ran:
2014-06-24 15:48:18 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) SMTP connect() failed. Mailer Error: SMTP connect() failed.
Here is my code:
<?php
require_once("..\path2\class.phpmailer.php");
date_default_timezone_set('America/Eastern');
include("..\path2\class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = True;
$mail->SMTPSecure = "SSL";
$mail->Host = "smtp.live.com";
$mail->Port = 465;
$mail->Username = "self#live.com";
$mail->Password = "pass1";
$mail->From="self#live.com";
$mail->Subject = $subject;
$mail->Body=$body;
$mail->AddAddress($email);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Telnet isn't very useful for testing encrypted connections - openssl is better. Try this on your server:
openssl s_client -crlf -connect smtp.live.com:465
That's currently not connecting for me from multiple countries, so perhaps Microsoft finally heeded the deprecation of SSL on port 465 back in 1998... Try this instead:
openssl s_client -starttls smtp -crlf -connect smtp.live.com:587
That's working well for me, so I suggest you make these changes to your code:
$mail->SMTPSecure = "tls";
$mail->Port = 587;

SMTP error with PHPMailer EHLO not supported

I have this code, which I want to use to send mails to my customers, PARAMETERS CENSORED (***):
include 'phpmailer/class.phpmailer.php';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->Host = "smtp.email.it";
$mail->Port = 25; // or 587 465
$mail->IsHTML(true);
$mail->SMTPSecure = 'tls';
$mail->Username = "***";
$mail->Password = "***";
$mail->SetFrom('***');
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress('***');
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
It connects but gives errors:
2013-10-13 09:13:25 CLIENT -> SERVER: EHLO *SITE_CENSORED*
2013-10-13 09:13:25 SMTP ERROR: EHLO command failed: Method EHLO is not supported.
2013-10-13 09:13:25 SMTP NOTICE: EOF caught while checking if connected
SMTP connect() failed.
Mailer Error: SMTP connect() failed.
Changing your port to 587 should work:
$mail->Port = 587; // or 587 465
I tried to telnet:
telnet smtp.email.it 25 //not working
telnet smtp.email.it 465 //not working
telnet smtp.email.it 587 //works

Categories