1

I'm sending a email using php:

use PHPMailer\PHPMailer\PHPMailer;

require 'Exception.php';
require 'PHPMailer.php';
require 'SMTP.php';
require 'PHPMailerAutoload.php';

$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "mijn.antagonist.nl"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = username;// GMAIL username
$mail->Password = pssword;// GMAIL password
$mail-> SMTPDebug = 2; //debug class when error

//Typical mail data
$query =  ("SELECT email FROM ps_customer where id_customer = 1");
$result = $query;
$to_email = (string)'@$result';
$subject = "test";
$txt = "test mail";
$headers = "From: test@test.nl";

//check of $to_email is not null
    if($to_email != null){

        mail($to_email,$subject,$txt,$headers);
        echo "mail is sent to : $to_email " ;

    } else {

        echo "failed";

    }

And this works for me, when I run this class it sends one email every time I run this class.

I'm trying to make it so that the emails will send automatically. I have heard about a cronjob but i can't figure out where and how to use it (I don't use linux).

Has someone an idea to make this work for me?

  • CronJobs are related to Linux. So, if it is not Linux you're using, what are you using? – KIKO Software Nov 22 '18 at 08:22
  • I'm using windows, so if you don't use linux is it possibol to use cronjob or? –  Nov 22 '18 at 08:35
  • 1
    in windows there "Scheduled Tasks" which is like cronjobs see https://stackoverflow.com/questions/295386/how-to-run-a-php-file-in-a-scheduled-task-windows-task-scheduler – R. Martin Nov 22 '18 at 08:40
  • so your saying that's not possibol to use cronjob on windows to automatically send a email?? –  Nov 22 '18 at 08:47
  • 1
    yes, it's not possible to use cronjob in windows (because it's a linux feature) but you can use Scheduled Tasks to send email (it works the same way as cronjob) – R. Martin Nov 22 '18 at 09:02
  • oké thank you very mutch for your help. –  Nov 22 '18 at 09:26

0 Answers0