我正在使用以下代码通过(PHPMailer)发送电子邮件。将变量传递给PHPMailer get_file_contents
该脚本从welcome.php(电子邮件模板)获取文件内容,如何将变量传递给模板?所以我可以自定义电子邮件模板。你可以做
// SEND EMAIL NOTIFICATION TO USER
$mail = new PHPMailer();
$body = file_get_contents('emails/templates/carer/welcome.php');
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("[email protected]","CareMatch");
$mail->SetFrom('[email protected]', 'Carematch');
$address = $_POST['email'];
$name = $_POST['firstname'] . $_POST['lastname'];
$mail->AddAddress($address, $name);
$mail->Subject = "Welcome to CareMatch";
$mail->AltBody = "We have assigned you a unique ID and generated you a password."; // optional, comment out and test
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
取代'的file_get_contents()',而调用解析为标签的模板,并与所要求的内容替换标签的功能。 – Dragos