I got this error using PHPMailer:
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.
and Here is the code :
function send_email($reciever = "e.salamati.taba#gmail.com", $mail_arr = '') { // This function will be upgraded later
$mail = new PHPMailer();
$body = $mail_arr['body'];
//$body = eregi_replace("[\]", '', $body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = true;
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "TLS"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "user"; // GMAIL username
$mail->Password = "pass"; // GMAIL password
$mail->SetFrom('e.salamati.taba#gmail.com', 'no-reply gmail.com');
$mail->Subject = $mail_arr['subject'];
$mail->MsgHTML($body);
echo "-----------------------";
$address = $reciever;
$mail->AddAddress($address, "e.salamati.taba#gmail.com");
if(! $mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
I have also see this, but still got the error, Is there any xampp config or something that cause the problem?
Thanks in advance...
Related
I made a code that sends mail using SMTP gmail with phpmailer. It worked fine in my local host.But when I deployed the code in heroku it is giving
royalmarutiservices.herokuapp.com is currently unable to handle this request.
HTTP ERROR 500
Here is the log of heroku
https://pastebin.com/raw/AgY11dBB
<?php
//echo $_POST['email'].$_POST['fname'].$_POST['phone'].$_POST['subject'];
include_once('PHPMailer/src/PHPMailer.php');
include_once('PHPMailer/src/SMTP.php');
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // 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
$mail->IsHTML(true);
$mail->Username = "user#gmail.com";
$mail->Password = "pass";
$mail->SetFrom($_POST['email']);
$mail->Subject = " Message from ".$_POST['fname'];
$mail->Body = $_POST['message'];
$mail->AddAddress('royalmaruti1996#gmail.com');
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
header('Location:index.php');
?>
Details about phpinfo()
~ https://royalmarutiservices.herokuapp.com/info.php
I am using smtp to send email from my website, The code I have used is given below. It is showing error. not working. I have enabled openssl in my website.
require 'phpmailer/PHPMailerAutoload.php';
define('GUSER', 'test#gmail.com'); // GMail username
define('GPWD', 'test11111'); // GMail password
$to='test11#gmail.com';
$body='hi';
$subject='request';
$from=GUSER;
$from_name='Support';
$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->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
//$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
//$mail->Port = 587;
$mail->Username = 'test#gmail.com';
$mail->Password = 'test11111';
$mail->SetFrom($from, $from_name);
$mail->isHTML(false);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to,'test');
echo !extension_loaded('openssl')?"Not Available":"Available";
if(!$mail->Send()) {
echo $error = 'Mail error: '.$mail->ErrorInfo;
//return false;
} else {
echo $error = 'Message sent!';
//return true;
}
showing error SMTP Error: Could not authenticate. SMTP connect() failed.
follow this settings in you're gmail account https://www.formget.com/codeigniter-gmail-smtp/
check with now username and password ..i've enabled it
<?php
include("class.phpmailer.php");
include("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->SMTPDebug = 2;
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->Port = 587; // set the port to use
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Username = "123#gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = "123#gmail.com";
$mail->FromName = "Webmaster";
$mail->AddAddress("asd#hotmail.com");
$mail->AddReplyTo("123#gmail.com", "Webmaster");
$mail->IsHTML(true);
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
It returns an error
2016-04-01 08:41:43 SMTP ERROR: Failed to connect to server: (0)
2016-04-01 08:41:43 SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message was not sent.Mailer error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I am hosting this php on my xampp local server. The extension=php_openssl.dll on php.ini is already uncommended.
Your configuration might be wrong. I believe that if you change your host into smtp.gmail.com it might solve your problem.
I noticed that you set security tls but you want to connect with ssl as well.
Change $mail->Host = "ssl://smtp.gmail.com"; into $mail->Host = "smtp.gmail.com"; and security to ssl.
From this answer:
$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->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "email#gmail.com";
$mail->Password = "password";
$mail->SetFrom("example#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("email#gmail.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
I'm trying to configure PHPMailer I've uploaded 1 file which is class.phpmailer.php and created another php file with this content:
<?php
require('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->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "myemail#gmail.com";
$mail->Password = "mypassword";
$mail->SetFrom("the same email address");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("the same email address");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
and i get nothing at all not a success message nor a failure message. http://www.mawk3y.net/mailtest/test.php
all answers are outdated now. Most current version (as of Feb 2018) does not have autoload anymore, and PHPMailer should be initialized as follows:
<?php
include_once(FCPATH.'PHPMailer/src/PHPMailer.php');
include_once(FCPATH.'PHPMailer/src/SMTP.php');
include_once(FCPATH.'PHPMailer/src/Exception.php');
$msj="My complete message";
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
//authentication SMTP enabled
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
//indico el puerto que usa Gmail 465 or 587
$mail->Port = 465;
$mail->Username = "xxxxxx";
$mail->Password = "xxxx";
$mail->SetFrom("xxxxxx#xxxxx.com","Name");
$mail->AddReplyTo("xxx#xxx.com","Name Replay");
$mail->Subject = "Test";
$mail->MsgHTML($msj);
$mail->AddAddress("xxxxxx#xxxxx.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
The problem is with the require method.
You first have to extract all file of phpMailer repository.
instead of writing
require('class.phpmailer.php');
you need to include path where your PHPMailerAutoload.php file extracted.so you can replace it with.
require('path-of-extracted-folder/PHPMailerAutoload.php');
for more reference you can visit it's GitHub link
https://github.com/PHPMailer/PHPMailer
I had same problem but I solved.This is the way I code
<?php
require 'PHPMailer-master/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
// Set PHPMailer to use the sendmail transport
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'abc#gmail.com'; // SMTP username
$mail->Password = 'abc'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Set who the message is to be sent from
$mail->setFrom('abc1#gmail.com', 'First Last');
//Set an alternative reply-to address
//Set who the message is to be sent to
$mail->addAddress('abc#gmail.com', 'Shehan');
//Set the subject line
$mail->Subject = 'Test Mail';
$mail->Body = 'This is Test Mail';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Im trying to send bulk of emails containing passwords to the students taking an exam in a particular subject.Now, Im having an error "SMTP Error: Could not connect to SMTP host. Mailer Error () SMTP Error: Could not connect to SMTP host." What could possibly be the problem?
my code as follows:
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
//date_default_timezone_set('America/Toronto');
require_once('PHPMailer-phpmailer-5.2.0/class.phpmailer.php');
include("PHPMailer-phpmailer-5.2.0/class.smtp.php"); //optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "localhost";
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPKeepAlive = true; // SMTP connection will not close after each email sent
$mail->Host = "mail.yahoo.com"; // sets the SMTP server*/
$mail->Port = 26;
$mail->Username = "***********#yahoo.com"; // SMTP account username
$mail->Password = "****************"; // SMTP account password
$mail->From = "*************#yahoo.com";
$mail->FromName = "Exam System";
//$mail->IsHTML(true);
while ($row_email = mysql_fetch_array ($email)) {
$mail->Subject = "Subject: ".$row_email['subject_description']."";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->Body = "This is your password for ".$row_email['exam_title']." : ".$row_email['pass_password']."";
$mail->AddAddress($row_email['stud_email']);
if(!$mail->Send()) {
echo "Mailer Error (" . str_replace("#", "#", $row_email['stud_email']) . ') ' . $mail->ErrorInfo . '<br />';
} else {
echo "Message sent to :" . $row_email['stud_email'] . ' (' . str_replace("#", "#", $row_email['stud_email']) . ')<br />';
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
mysql_free_result($email);
?>
Try this...
add this code for Set secutiry
// if you're using SSL
$mail->SMTPSecure = 'ssl';
// OR use TLS
$mail->SMTPSecure = 'tls';
Try with gmail, as i am not aware of Yahoo's SMTP server. [Also, use the gmail credentials (username, password)]
$mail->Host = "smtp.gmail.com";
function SendMailWithGmailSMTP($author, $email, $text)
{
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost"; // Sets the SMTP hosts
$mail->Port = 587; // Sets the default SMTP server port.
$mail->SMTPAuth = false; // Sets SMTP authentication. Utilizes the Username and Password variables.
$mail->Username = "...#gmail.com";
$mail->Password = "...";
$mail->From = $email;
$mail->FromName = $author;
$mail->CharSet = "ISO-8859-9";
$mail->AddAddress("...#gmail.com");
$mail->Subject = "Hi. This is a Subject!";
$mail->IsHTML(true);
$mail->Body = $text;
if($mail->Send()) return true; else echo '<script language="javascript">alert("'.$mail->ErrorInfo.'");</script>';
}
Write this function for send mail and call this function like this:
SendMailWithGmailSMTP("Aziz Yılmaz", "...#gmail.com", "Bla bla bla")