I am sending a report by calling this PHP page daily on my browser. It (too often) sends emails twice (even if I make sure to open a new tab each time).
What's wrong with the code + How can I prevent it?
Here is the code:
<?php
require ("/home/phpmailer/PHPMailer-master/PHPMailerAutoload.php");
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'USERNAME@DOMAIN.com'; // SMTP username
$mail->Password = 'PASSWORD'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = 'FROM-NAME@DOMAIN.com';
$mail->FromName = 'FROM NAME';
$mail->ClearAddresses();
$mail->addAddress('email1@ABC.com', 'CLARA'); // Add a recipient
$mail->addCC('email@@ABC.com', 'TOM'); // Add a CC recipient
$mail->addReplyTo('email2@ABC.com', 'Info');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'EMAIL SUBJECT TITLE';
$mail->Body = file_get_contents('http://ADDRESS-OF-THE-FILE.PHP');
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
$mail->ClearAddresses();
}
?>
I am going to guess that you are using Google Chrome and "Prefetch resources to load pages more quickly" is enabled. Essentially Chrome is fetching the URL before you finish typing so when you finish typing and hit enter then you are requesting it again.
Either turn off prefetching or save the URL to a bookmark and click the bookmark when you need to run the task.