PHPMailer_v5.1- SMTP Error: Could not authenticate - php

I have the below code and I am getting the following error:
I am using the version PHPMailer_v5.1. I tried another version but it did not work. Any Ideas?
SMTP Error: Could not authenticate
$mail = new PHPMailer(false); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.easyname.eu"; // SMTP server
$mail->Port = 465;
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Username = "info#mydomain.net"; // SMTP account username
$mail->Password = "*****"; // SMTP account password
$mail->AddReplyTo("$fromEmail", "$from");
$mail->AddAddress("$toEmail", "$toName");
$mail->SetFrom("$fromEmail", "$from");
$mail->Subject = "New enquiry to example (SUBJECT:'$subject')";
$mail->AltBody = "$message"; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML("$message");
$mail->Send();
if($settings['cc_sender'])
{
$mail = new PHPMailer(false); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.easyname.eu"; // SMTP server
$mail->Port = 465;
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Username = "info#mydomain.net"; // SMTP account username
$mail->Password = "******"; // SMTP account password
$mail->AddReplyTo("no-reply#mydaomain.net", "example Website");
$mail->AddAddress("$fromEmail", "example Enquiry");
$mail->SetFrom("info#mydomain.net", "example Enquiry");
$mail->Subject = "Your enquiry from example (SUBJECT:'$subject')";
$mail->AltBody = "$message"; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML("$message");
$mail->Send();
}

Related

PHPmailer script runs without problems but doesn't send anything

I have a really simple PHP code for sending emails. The page is loading without any errors but it doesn't seem to do anything.
also, I am new to PHP and I don't really know how to debug this stuff.
I'll really appreciate a little help (: thank you!
<?php
require_once('PHPMailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure ='ssl';
$mail->Host = 'smtp.gmail.com';
$mail->port = '456';
$mail->isHtml();
$mail->Username = 'lagofbot#gmail.com';
$mail->Password = 'lago9876543s';
$mail->Subject = 'Hello';
$mail->Body = "test";
$mail->From = 'no-replay';
$mail->FromName = 'no-replay';
$mail->AddAddress('mrxvr123#gmail.com');
$mail->send();
?>
change your code like this and see if it will show you any errors
$mail = new PHPMailer();
try {
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure ='ssl';
$mail->Host = 'smtp.gmail.com';
$mail->port = '456';
$mail->isHtml();
$mail->Username = 'lagofbot#gmail.com';
$mail->Password = 'lagofbot258258#258258';
$mail->Subject = 'Hello';
$mail->Body = "test";
$mail->From = 'no-replay';
$mail->FromName = 'no-replay';
$mail->AddAddress('mrxvr123#gmail.com');
$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
Try with this
require __DIR__.'../phpmailer/src/PHPMailer.php'; //configure according your files
require __DIR__."./phpmailer/src/Exception.php";
require __DIR__."../phpmailer/src/SMTP.php";
$mail = new \PHPMailer\PHPMailer\PHPMailer(); // create a new object
$mail->isSMTP(); // enable SMTP
$mail->SMTPDebug = 2; // 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->Username = ""; //GMAIL ACCOUNT EMAIL ID
$mail->Password = ""; // GMAIL ACCOUNT PASSWORD
$mail->SetFrom("",''); // FROM THIS MAIL ID & SET AS DEFINE IN SECOND PARAMETER
$mail->addAddress($email); // `TO` FIELD IN MAIL
$mail->IsHTML(true);
if (!$mail->Send()) {
return true;
} else {
return false;
}
And don't forget to enable less secure apps if you use gmail.
Hope this helps :)

SMTP mail sending not working

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

Error while sending email using php

SMTP -> ERROR: Failed to connect to server: An attempt was made to access a socket in a way forbidden by its access permissions. (10013) The following From address failed: info#gmail.com : Called Mail() without being connected
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "gmail.com";
$mail->Password = "password";
$mail->From = "info#gmail.com";
$mail->FromName = "name.com";
$mail->Subject = "Register";
$mail->MsgHTML($userMsg);
$mail->AddAddress("email address", "name");
//$mail->AddAddress($rowUser['user_email'], $rowUser['user_name']);
$mail->send();
$mail->ClearAllRecipients();
TLS is correct, you could try SSL, change port to 465. Check your credentials. Is on-screen Username "gmail.com"?
Try this:
$mail = new PHPMailer();
$mail->IsSMTP(); // enable SMTP
$mail->CharSet = "UTF-8";
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "yourname#gmail.com";
$mail->Password = "yourpassword";
$mail->SetFrom("example#gmail.com");
$mail->Subject = $subject;
$mail->Body =$body;
$mail->AddAddress($email);
if(!$mail->Send())
{
return FALSE;
}

While sending a email such errors occurs ...not working its live

SMTP -> ERROR: Failed to connect to server: An attempt was made to access a socket in a way forbidden by its access permissions. (10013)
The following From address failed: info#gmail.com : Called Mail() without being connected.
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "name#gmail.com";
$mail->Password = "password";
$mail->From = "info#gmail.com";
$mail->FromName = "name.com";
$mail->Subject = "Register";
$mail->MsgHTML($userMsg);
$mail->AddAddress("useremail", "username");
$mail->send();
$mail->ClearAllRecipients();

PHPMailer - make the sender mail variable

I'm using php mailer and i cant specify the sender mail , i want to be a variable every one type his email to be here , but it cant be done i must type my email and my password , so anyone know how it can be done
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$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 = "usermail"; // GMAIL username
$mail->Password = ""; // GMAIL password
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->addReply=$_POST['email'] ;
$mail->addAddress=$_POST['email'];
$mail->Subject=$_POST['subject'];
$mail->Body=$_POST['message'] .$_POST['email'];
$mail->Sender=$_POST['email'];
try this code
$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");
#$mail->Send()
Go through this link -> Own-Email-System-using-SMTP-and-PHPMailer
OR,
Please elaborate your issues so that i can help you properly .
NOTE:If "Less secure app access" is turned off for your Gmail account, you have to turn it on. => Click Here To see . Is it ON or OFF
<?php
require_once 'vendor/autoload.php';
$mail = new PHPMailer\PHPMailer\PHPMailer;
//Enable SMTP debug mode
$mail->SMTPDebug = 0;
//set PHPMailer to use SMTP
$mail->isSMTP();
//set host name
$mail->Host = "smtp.gmail.com";
// set this true if SMTP host requires authentication to send mail
$mail->SMTPAuth = true;
//Provide username & password
$mail->Username = "YOUR_GMAIL_EMAIL_ID";
$mail->Password = "YOUR_GMAIL_PASSWORD";
$mail->SMTPSecure = "tls";
$mail->Port = 587;// Enter port number
$mail->ClearReplyTos();
$mail->addReplyTo("YOUR_GMAIL_EMAIL_ID", $_POST['name']); //$_POST['name'] => YOUR_GMAIL_NAME . You Can directly give "YOUR_GMAIL_NAME"
$mail->SetFrom("YOUR_GMAIL_EMAIL_ID", $_POST['name']);
$mail->addAddress($_POST["email"]); //TO WHOM U R SENDING MAIL
//Subject
$mail->isHTML(true);
$mail->Subject =" ".$_POST['subject']." ";
$body = "<html>
<head> </head>
<body>
".$_POST['message']." <br>
</body>
</html>";
$mail->MsgHTML($body);
if(!$mail->send()) {
$error_message = "Mailer Error : ". $mail->ErrorInfo;
echo $error_message;
} else {
echo "Email Sent Successfully";
}
?>

Categories