Schedule emails using cron jobs.
I would like to schedule email that will be sent before 24 hours. I use cron jobs to execute my php script but didn't work. Mind if anyone to check why?
My index.php:
0){
while($row = $sql->fetch_assoc()) {
echo '
Shop ID: '.$row['id'>; $time_ago = strtotime($row['currdate'>); echo '
Time ago: '.$time_ago; $current_time = time(); echo '
Current time: '.$current_time; $time_difference = $current_time - $time_ago; echo '
Time difference: '.$time_difference; $seconds = $time_difference; $hours = round($seconds / 3600); echo '
Hour: '.$hours; echo '
'; if($hours > 10) { require_once 'PHPMailerAutoload.php'; $mail = new PHPMailer; $mail->SMTPDebug = 2; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'mail.jrmnsfamily.com'; // Specify main and backup SMTP servers //$mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'admin@jrmnsfamily.com'; // SMTP username $mail->Password = ''; // SMTP password //$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 587; // TCP port to connect to $mail->setFrom('admin@jrmnsfamily.com', 'admin'); $mail->addAddress('anasuharosli@gmail.com', 'Siti Anasuha'); // Add a recipient //$mail->addAddress('ellen@example.com'); // Name is optional //$mail->addReplyTo('info@example.com', 'Information'); //$mail->addCC('cc@example.com'); //$mail->addBCC('bcc@example.com'); //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name $mail->isHTML(true); // Set email format to HTML $mail->Subject = '[REMINDER] Invoice #'.$row['id'>; $mail->Body = 'You have 1 hour for payment before cancelled.'; //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } } } } ?>
Shop ID: '.$row['id'>; $time_ago = strtotime($row['currdate'>); echo '
Time ago: '.$time_ago; $current_time = time(); echo '
Current time: '.$current_time; $time_difference = $current_time - $time_ago; echo '
Time difference: '.$time_difference; $seconds = $time_difference; $hours = round($seconds / 3600); echo '
Hour: '.$hours; echo '
'; if($hours > 10) { require_once 'PHPMailerAutoload.php'; $mail = new PHPMailer; $mail->SMTPDebug = 2; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'mail.jrmnsfamily.com'; // Specify main and backup SMTP servers //$mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'admin@jrmnsfamily.com'; // SMTP username $mail->Password = ''; // SMTP password //$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 587; // TCP port to connect to $mail->setFrom('admin@jrmnsfamily.com', 'admin'); $mail->addAddress('anasuharosli@gmail.com', 'Siti Anasuha'); // Add a recipient //$mail->addAddress('ellen@example.com'); // Name is optional //$mail->addReplyTo('info@example.com', 'Information'); //$mail->addCC('cc@example.com'); //$mail->addBCC('bcc@example.com'); //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name $mail->isHTML(true); // Set email format to HTML $mail->Subject = '[REMINDER] Invoice #'.$row['id'>; $mail->Body = 'You have 1 hour for payment before cancelled.'; //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } } } } ?>
Please sign in to leave a comment.
Comments
0 comments