I have a phpmailer/phpmailer script which works perfectly well as code but which is being blocked intermitently by gmail.
The code involves my gmail address and password and when I first tried it out gmail sent a message saying that they did not like the security of the source (i.e. the web site I was sending the message from). However they offered me the option of allowing the mail to be sent from "less secure sources". I selected this option and the mailer worked fine for about a week. Then I got a message saying that the mailings were blocked because someone had used my password. However from the timings they gave it is pretty likely the message came from my web site which I was busy testing. I can't really do with a mailer that works part time. How to get round this ?
I have included the code, but it is standard stuff as far as I know.
// Now try to do the mailing
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
// The following works OK, but the first time it is used GMAIL will probably send a message
// saying that the source is not secure enough and give you the option to allow the sending
// of messages from less secure sites. I did this here.
$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 = "mymonikcker@gmail.com"; // GMAIL username
$mail->Password = "mypassword"; // GMAIL password
$mail->SetFrom('source@tushino-payments.com', 'Latest data'); // Latest Data will appear as the minor subject heading
// The recipient
$address = "xxx@yahoo.com";
$mail->AddAddress($address, "Mr Smith");
// Heading and the actual message
$mail->Subject = "Testing of emailer attachments";
$mail->Body = $final_string;
// Add an attachment
$mail->addAttachment('Folder/Sheet.txt');
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent and transaction completed";
}