I need a help in email sending in PHP. Am actually trying to send email using PHP mailer. Somehow for some of the mail ids am able to send the email but for some other email ids am unable to send. I receive an email in gmail stating 'Signin attempt prevented.' Can somebody help me know where do I need to change the settings in my gmail account in order to make my PHP code to send emails?
require("phpmailer/class.PHPMailer.php");
require("phpmailer/class.smtp.php");
$f_pointer=fopen("test.csv","r"); // file pointer
$emails = array();
while (($data = fgetcsv($f_pointer, 1000, ",")) !== FALSE) {
$num = count($data);
$emails[] = $data[1];
}
foreach($emails as $key=>$val){
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "tls://smtp.gmail.com:587"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "abc"; // SMTP username
$mail->Password = "some password"; // SMTP password
$mail->From = "abc@gmail.com";
$mail->FromName = "abc";
$mail->AddAddress($val);
$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. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
}
This is working fine for some example 'abc@gmail.com', but when I use other username, password and email say 'xyz@gmail.com' I receive an email in my inbox stating 'signin attempt failed.' Help appreciated.
It has been resolved by turning on the permission for less secure apps in the link https://www.google.com/settings/security/lesssecureapps