try to use phpmailer but it not work: SMTP Error: Could not authenticate - phpmailer

$mail= new PHPmailer();
$mail-> IsSMTP();//telling the class to use SMTP
$mail->Host = gethostbyname('smtp.gmail.com');//SMTP server
$mail->SMTPDdebug =2; //enables SMTP debug information
$mail->SMTPAuth = true;//enable SMTP authentication
$mail->SMTPSecure = "tsl";//set the prefix to the server
$mail->Port =587;//set the SMTP port for thr GMAIL server
$mail->Username = "andriyvyhor#gmail.com";//GAMAIL username
$mail->Password ="andriyvyhor";
$mail->SetFrom=("andriyvyhor#gmail.com");
$mail->AddAddress("andriyvyhor#gmail.com");
$mail->Subject="TEXT";
$mail->Body="You sell your shares";
if(!$mail->Send())
{
echo "Mailer erro:".$mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
}
am getting this error
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.

Related

PHPMailer can't send via postfix

I already setup postfix in my debian linux VPS.
I can send email via ssh console using postfix.
I can send email using PHPMailer using my gmail account.
I can receive email in my debian linux VPS account.
Then I want to send email using PHPMailer via Postfix using my debian linux vps account. But it's failed with log below.
SERVER -> CLIENT: <br>
CLIENT -> SERVER: EHLO android<br>
SERVER -> CLIENT: <br>
SMTP ERROR: EHLO command failed: <br>
SMTP NOTICE: EOF caught while checking if connected<br>
SMTP Error: Could not connect to SMTP host.<br>
How to send email using PHPMailer using postfix ? should i use sasl ?
My sendmail.php
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Subject = 'hello postfix phpmailer';
$mail->msgHTML(file_get_contents('contentemail.html'), dirname(__FILE__));
$mail->Host = 'yyyy.zzzz.com';
$mail->Username = "xxxx";
$mail->setFrom('xxxx#yyyy.zzzz.com', 'Ceramah Islam');
$mail->addReplyTo('xxxx#yyyy.zzzz.com', 'Ceramah Islam');
$mail->Password = "aaaaaa";
$mail->addAddress('bbbb#gmail.com', 'bbbb');
$mail->send();
I think the problem is caused by the "snakeoil" certificate and private key that come with Postfix. The trick is not to verify them. Here is what I found worked:
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = "localhost";
$mail->Port = 25;
$mail->SMTPSecure = "tls";
$mail->SMTPOptions = array
(
'ssl' => array
(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->setFrom('server#example.org', 'My Server');
$mail->addAddress('user#example.com', 'My User');
$mail->Subject = 'Message from PHPMailer and Postfix';
$mail->Body = 'Whatever';
if ($mail->send())
// SMTP message send success
{
// Put success logic here
}
else
// SMTP message send failure
{
// Put failure logic here
}

PhpMailer is not working on live server

PhpMailer is working fine in localhost. But when I've uploaded it on a live server it is not working.
SMTP -> ERROR: Failed to connect to server: Network is unreachable
(101) The following From address failed: facefinder2#gmail.com :
Called Mail() without being connected Mailer Error: The following From
address failed: facefinder2#gmail.com : Called Mail() without being
connected
I'm using the following code:
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = '587';
$mail->SMTPDebug = 1;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'facefinder2#gmail.com';
$mail->Password = '************';
$mail->SetFrom("facefinder2#gmail.com");
//$mail->FromName = "FaceFinder";
$mail->addAddress($receiver, $name);
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = $plain_body;
if(!$mail->send()) {
//return false;
echo "Mailer Error: " . $mail->ErrorInfo; die();
} else {
return true;
//echo "Message has been sent successfully";
}
What can I do to solve this?
Failed to connect to server: Network is unreachable (101)
It seems your hosting environment is blocking outbound connection to gmail (either by domain or port) which tends to happen when using shared hosting (spam prevention).
Basically you have to check with your service provider

phpmailer No Relay Access Allowed Error

My website is hosted on godaddy, and I just figured out that my website is no more sending emails through phpmailer since last few months. I uploaded the latest version of phpmailer but still no success. The online web mail of my website runs fine. If I use php's "mail" function, it does send emails to gmail, but not to yahoo accounts.
I tried all the three ports 25, 465, and 587, but no luck
I am getting the following error from phpmailer:
SERVER -> CLIENT: 554 p3plsmtpa07-10.prod.phx3.secureserver.net ESMTP No Relay Access Allowed From 50.63.196.51
CLIENT -> SERVER: EHLO lostandfound.pakproject.com
SERVER -> CLIENT:
SMTP ERROR: EHLO command failed:
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
Following is my code that I am trying to test. (User name, passwords, emails are changed...)
<?php
date_default_timezone_set('Etc/UTC');
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = "smtpout.... my_server";
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = "here_i_used_my_website_email";
$mail->Password = "here_password";
$mail->setFrom('website_email', 'From name');
$mail->addReplyTo('website_email', 'From name');
$mail->addAddress('another_email', 'name_used_here');
$mail->Subject = 'About the task';
$mail->Body = 'This is email body';
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
$mail->SMTPSecure = false;
$mail->SMTPAuth = false;
It worked for me.
Keep in mind
https://co.godaddy.com/help/mail-server-addresses-and-ports-for-business-email-24071**
I was able to resolve my issue with the following code/settings of phpmailer
<?php
$recipient = "abc#def.com"
$subject = "Subject here";
$emailBody = "This is body";
// PHP MAILER CODE STARTS FROM HERE //
require '../phpmailermaster/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtpout.secureserver.net'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxx#yyyy.com'; // SMTP username
$mail->Password = '3344123'; // SMTP password
//$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
//$mail->Port = 465;
$mail->Port = 80; // TCP port to connect to [THIS PORT ALLOWING EMAILS]
$mail->setFrom('xxx#yyyy.com', 'hello');
//$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress($recipient); // Name is optional
//$mail->addReplyTo('info#example.com', 'Information');
//$mail->addBCC('bcc#example.com');
//$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 = $subject;
$mail->Body = $emailBody;
$mail->AltBody = $emailBody;
if(!$mail->send())
{
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else
{
echo 'Message has been sent';
}
// PHP MAILER CODE ENDS HERE ==
?>

how to send mail using phpmailer with smtp.office365.com

I am using below code to send mail but this is not working for me. Please help me to resolve this problem.
require 'class.phpmailer.php';
require 'class.smtp.php';
$subject="Test PHP mailer";
$message="Hi";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier - TLS/SSL
$mail->Host = "smtp.office365.com"; // sets GMAIL as the SMTP server - smtp.gmail.com
$mail->Port = 587; // set the SMTP port for the GMAIL server - Gmail SMTP port (SSL): 465 **** Gmail SMTP port (TLS): 587
$mail->Username = ""; // other email address
$mail->Password = ""; // password
$mail->SetFrom("customercare#test.com", "John");
$mail->addReplyTo('customercare#test.com', 'John');
$mail->Subject = $subject;
//$mail->IsHTML(true);
$mail->MsgHTML($message);
$mail->AddAddress('abc#example.com');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
It display error message:
Mailer Error: SMTP Error: data not accepted.SMTP server error: DATA END command failed Detail: 5.7.60 SMTP; Client does not have permissions to send as this sender SMTP code: 550
Looking at the error message, it's not a problem with the code, but a problem with the permissions for the user your are trying to send as.
You will either need to get the user you're trying to send as to allow their account to be used in such a way, or you'll have to find a different smtp service to use.

Failed to connect to server: Connection timed out (110)SMTP Connect() failed. Message was not sent.Mailer error: SMTP Connect() failed

This is my code and still it is not sending the mail. What could be the problem?
require 'class.phpmailer.php';// path to the PHPMailer class
require 'class.smtp.php';
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->Host="smtp.gmail.com";
$mail->SMTPSecure='tls';
$mail->Port =465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "mymailgmail.com"; // SMTP username
$mail->Password = "mypassword"; // SMTP password
$mail->SMTPDebug = 1;
$mail->AddAddress("mymail#gmail.com","Title");
$mail->SetFrom($visitor_email, $name);
$mail->AddReplyTo($visitor_email,$name);
$mail->Subject = "Message from Contact form";
$mail->Body = $user_message;
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
// header('Location: thank-you.html');
}
I had similar issue sometime back. It turned out that the connection was attempted using ipv6 address. It worked fine after removing IPv6 address from network interface.

Resources