我正在使用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)。
有人有办法帮我解决这个问题吗?
暂无答案!
目前还没有任何答案,快来回答吧!