自动发送电子邮件(定时作业)

时间:2018-11-22 08:19:31

标签: php mysql cron heidisql

我正在使用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";

    }

这对我有用,当我运行此类时,每次运行此类时它都会发送一封电子邮件。

我正在尝试使其能够自动发送电子邮件。我听说过cronjob,但是我不知道在哪里以及如何使用它(我不使用linux)。

有人想帮我这个忙吗?

0 个答案:

没有答案