PHPMailer wont send mails - php

I have this PHPMailer: https://github.com/PHPMailer/PHPMailer/
my code is this:
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'kms-play.it'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'noreply#kms-play.it'; // SMTP username
$mail->Password = 'pass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'noreply#kms-play.it';
$mail->FromName = 'KMS-Play';
$mail->addAddress('evolutio#kms-play.it', 'Lars Mehrhoff'); // Add a recipient
#$mail->WordWrap = 50; // Set word wrap to 50 characters
#$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
#$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
#$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';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
and the error is:
2013-12-15 15:02:23 CLIENT -> SERVER: EHLO local.kms-play.it 2013-12-15 15:02:23 CLIENT -> SERVER: STARTTLS 2013-12-15 15:02:23 SMTP ERROR: STARTTLS command failed: 502 5.5.1 Error: command not implemented 2013-12-15 15:02:23 CLIENT -> SERVER: QUIT SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.

You have 2 options:
1 - As TLS is not active comment this line:
$mail->SMTPSecure = 'tls';
It will work but is not good to send mails without sign them.
2 - Make sure to activate TLS and the EHLO command should return:
EHLO myfriend
2016-10-27 01:15:07 SERVER -> CLIENT: 250-server.urutecno.net
Hello mail.myfriemd.com [216.111.111.111]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP

Just config issue.
update< human -> goto web ::https://github.com/PHPMailer/PHPMailer/releases
get --> PHPMailer-5.2-stable and browse to examples\mailing_list.phps
add the followin config files to the file and it will work out of the box.
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->isSMTP();
$mail->SMTPAutoTLS = false;
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
for sure it will work

I guess this might be wrong:
$mail->Host = 'kms-play.it';
Is that really your SMTP host? Usually it's something like smtp.kms-play.it. Best check with your hosting provider.

Related

How to configure gmail smtp and phpmailer?

I want to know where the problem is because I get authentication error.
I already have a few gmail accounts,
I created a new one for my website,
I added a new email in "Account and import" to my old gmail account.
I copied my new email username and password to phpmailer code
include_once('phpmailer/class.phpmailer.php');
include_once('phpmailer/class.smtp.php');
//6nb5Drv;
function sendmail(){
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com"; // specify main and backup server
$mail->Port = 587; // Set the SMTP port i tried and 457
$mail->Username = 'newmail#gmail.com'; // SMTP username
$mail->Password = 'newmailpass'; // SMTP password
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->From = 'from#yahoo.com';
$mail->FromName = 'From';
$mail->AddAddress('to#gmail.com', 'To'); // Add a recipient
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
}
sendmail();
But I get an authentication error.
What is wrong?
Probably something with the credentials, how do I configure gmail smtp?
Debug report:
2015-12-04 17:56:15 CLIENT -> SERVER: EHLO www.site.co
2015-12-04 17:56:15 CLIENT -> SERVER: STARTTLS 2015-12-04
17:56:15 CLIENT -> SERVER: EHLO www.site.co 2015-12-04
17:56:15 CLIENT -> SERVER: AUTH LOGIN 2015-12-04 17:56:15 CLIENT ->
SERVER: UHJlZGljdG9sb2d5 2015-12-04 17:56:15 CLIENT -> SERVER:
U2dHZlB0VHZUbTZ1SW9ZMi1qTlNCQQ== 2015-12-04 17:56:17 SMTP ERROR:
Password command failed: 435 4.7.8 Error: authentication failed:
UGFzc3dvcmQ6 2015-12-04 17:56:17 SMTP Error: Could not authenticate.
2015-12-04 17:56:17 CLIENT -> SERVER: QUIT 2015-12-04 17:56:17 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
According to this post:
PHPMailer - SMTP ERROR: Password command failed when send mail from my server, in some case, you have to specify google that this is not a suspicious activity and activate some less secure option in your account.
Assuming this is the right password...

Getting error SMTP connect() failed phpmailer with localhost

I'm getting error SMTP connect() failed phpmailer with localhost:
2015-09-10 09:34:48 Connection: opening to ssl://smtp.gmail.com:587,
timeout=300, options=array ( ) 2015-09-10 09:34:48 SMTP ERROR: Failed
to connect to server: (0) 2015-09-10 09:34:48 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
Is it phpmailer cannot run at localhost?
If I want really run at localhost how can I change the code?
I tried using mailto function is work for me but I want change whole thing.
can give any suggestion. I really want to learn it.
This is the code from github:
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mygmail#gmail.com'; // SMTP username
$mail->Password = 'mygmailpassword'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//$mail->Host = 'tls://smtp.gmail.com:587';
$mail->From = 'ikramlim#gmail.com';
$mail->FromName = 'Mailer';
$mail->addAddress('ikramlim#gmail.com', 'Joe User'); // Add a recipient
$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';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
PHPMailer is normally working on all systems.
I think you have an old openssl extension or your extension is not enabled. Check that with a phpinfo() if there is openssl enabled.
If not then enable it in your php.ini.
And the other way is that it seems that Google has some problems. When i try to send an Email at the moment i have connection problems with Thunderbird, too. I have to try it some times to connect to gmail.
My suggestion is that please try using 'tls' with port 587 instead of 'ssl' with port 587.
Also check whether you are including class.phpmailer.php(ie: require 'class.phpmailer.php';) , If you are doing please comment it and give a try.

SMTP ERROR: Failed to connect to server: Connection timed out (110)

Connection: opening to smtp.mandrillapp.com:587, timeout=300, options=array ()
SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed.
Message could not be sent.Mailer Error: SMTP connect() failed.
I used mandrillAPI to send email. It works on my localhost. I can send mails from my localhost. But when I used this on the test server it is not connecting to the mandrill server. It shows the above error. I checked the port and it is open. I can use gmail smtp from my server. It works fine. But I need to use mandrillAPI. I also added DKIM and SPF record on domain. But still not connecting to the smtp.mandrillapi.com
here is the code I used.
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com'; // Specify main and backup server
$mail->Port = 587; // Set the SMTP port
$mail->SMTPDebug = 4;
$mail->Debugoutput='html';
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'example#gmail.com'; // SMTP username
$mail->Password = 'apikey'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'example#gmail.com';
$mail->FromName = 'example';
$mail->AddAddress('example#gmail.com', 'Nidheesh'); // Add a recipient
// Name is optional
$mail->addReplyTo('example#gmail.com');
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
?>
`

PHPMailer SMTP connect failed

I'm trying to send email over Mandrill with PHPMailer but withouth sucess (testing on localhost).
Can someone tell me where is the problem?
This is the verbose information from PHPMailer:
2014-04-27 17:51:06 SERVER -> CLIENT: 220 smtp.mandrillapp.com ESMTP
2014-04-27 17:51:06 CLIENT -> SERVER: EHLO 127.0.0.1
2014-04-27 17:51:06 SERVER -> CLIENT: 250-ip-10-107-129-238
250-PIPELINING
250-SIZE 26214400
250-STARTTLS
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250 8BITMIME
2014-04-27 17:51:06 CLIENT -> SERVER: STARTTLS
2014-04-27 17:51:06 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2014-04-27 17:51:06 CLIENT -> SERVER: QUIT
2014-04-27 17:51:16 SERVER -> CLIENT:
2014-04-27 17:51:16 SMTP ERROR: QUIT command failed: SMTP connect() failed. Message could not be sent.
Mailer Error: SMTP connect() failed.
Here is my code:
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com'; // Specify main and backup server
$mail->Port = 587; // Set the SMTP port
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'example#mail.com'; // yes, I have entered my username mail
$mail->Password = 'xxxxxxxxxxxx-xxxxxxxxx'; // yes, API key is here
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from#example.com';
$mail->FromName = 'Your From name';
if($test_mode) {
$mail->SMTPDebug = 2;
$mail->AddAddress('mymail#gmail.com');
} else {
$mail->AddAddress($email);
}
$mail->IsHTML(true); // Set email format to HTML
$mail->WordWrap = 70; // Set word wrap to 70 characters
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->Subject = 'Subject';
$mail->Body = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
//redirect to
echo 'Message could not be sent.<br>';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
EDIT:
I can delete this:
$mail->SMTPSecure = 'tls';
and it will work! But now the encryption is disabled. Why is this not working with encryption enabled?
Uncoment php_openssl.dll in php.ini
Is the timezone set correctly?
include timezone definitions before loading phpmailer
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
$mail = new PHPMailer();
Also, if you're trying it from a gmail domain, it ught have been blocked. check at: https://security.google.com/settings/security/activity?hl=pt_BR

PHPMailer echo's from successful sent email

Hello I finally got PHPMailer to work with Google but now I am finding out that I am getting this output to the screen after the message has been sent.
SMTP -> FROM SERVER:220 mx.google.com ESMTP f34sm21891943qco.35
SMTP -> FROM SERVER: 250-mx.google.com at your service, [76.28.109.170] 250-SIZE 35651584 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH 250 ENHANCEDSTATUSCODES
SMTP -> FROM SERVER:250 2.1.0 OK f34sm21891943qco.35
SMTP -> FROM SERVER:250 2.1.5 OK f34sm21891943qco.35
SMTP -> FROM SERVER:354 Go ahead f34sm21891943qco.35
SMTP -> FROM SERVER:250 2.0.0 OK 1276700936 f34sm21891943qco.35
I was wondering if there was any way to remove this output so the users don't see it?
Set the $phpmailer->SMTPDebug property to 0, you probably left it on debug (at least, I detect some work has been done from the 'finally'). http://phpmailer.worxware.com/index.php?pg=properties
<?php
require("PHPMailer/PHPMailerAutoload.php");
$mail = new PHPMailer;
//Enable SMTP debugging. 3 disable=0
$mail->SMTPDebug = 0;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = "smtp.gmail.com";//or your domain
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "your email";
$mail->Password = "your email password";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "tls";
//Set TCP port to connect to
$mail->Port = 587;
$mail->From = "your email";
$mail->FromName = "your name";
$mail->addAddress($userMail, $uname);
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
//$mail->AltBody = "This is the plain text version of the email content";
// you can also comment the echos here out
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
?>
enter code hereCheck this image at line 8.
You can also comment out the if(!$mail->send()){ } else{} block

Categories