我正在使用以下代碼通過(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