我在WordPress插件中制作了一个电子邮件系统,用于发送带有以下代码的电子邮件:
include(PLUGIN_DIR.\'config/class_phpmailer.php\');
$email = new PHPMailer();
$email->From = get_option(\'admin_email\');
$email->FromName = \'my name\';
$email->Subject = $subject;
$email->Body = $body;
foreach($emails as $mail) {
if(is_email($mail)) {
$email->addAddress($mail);
}
}
if($name) {
$att = PLUGIN_DIR.\'uploads/\'.date(\'Ymd\').\'_\'.$name;
$email->AddAttachment($att);
}
// check if email is sent or not
if(!$email->Send()) {
echo "Message was not sent <br />PHPMailer Error: " . $email->ErrorInfo;
}
else {
echo "Message has been sent";
$_POST = array();
}
这很有效。在线测试并发送给所有测试过的电子邮件。我可以这样做吗?我的意思是,phpmailer类不是WP的原生类。这是错的吗?最好使用原生WP phpmailer吗?如果是,我该怎么做?
提前谢谢。