phpMailer send a smtp email - php

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;

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

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 not working in my server

I built a droplet with Ubuntu with DigitalOcean and I'm trying to configure it to send emails with SMTP.
I know DigitalOcean blocks SMTP over IPv6 but not over IPv4 so I disabled IPv6 as this post says.
My script still doesn't work. I've tried with ports 25, 465 and 587. TLS and SSL.
I've installed sendmail for Ubuntu 14.04 but not working.
This is my script:
<?php
require 'mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$to = $_GET['email'];
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'rafawins#gmail.com';
$mail->Password = '***';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('rafawins#gmail.com', 'Rafael');
$mail->addAddress($to);
$mail->isHTML(true);
$mail->Subject = 'Subject';
$contents = ob_get_contents();
$mail->Body = "ao!";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
print_r(error_get_last());
?>
The error presented is:
SMTP connect() failed.
I'm interested in sending email using SMTP so ->isSMTP() is required!
Where am I wrong?
Thank you very much.
EDIT:
doing: telnet smtp.gmail.com 587
I get:
Trying 74.125.133.108...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 smtp.gmail.com ESMTP w6sm13897014wjy.31 - gsmtp
and doing: openssl s_client -connect smtp.gmail.com:465 I get an answer as well...
What's wrong?
Beware of using Gmail from different devices. google doesn't allow and block immediately a location from where an account is used where it isn't supposed to use (in the eyes of google ofcourse).
On live server for send Mail using SMTP, Do it.
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
and Comment $mail->IsSMTP();
It's Working For Me....
Try commenting out line 8.
// $mail->isSMTP();

SMTP connect error using phpmailer

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.

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