php邮件html模板下载,PHP Mailer与HTML模板和发送变量

基本上我试图这样做

这是我的代码

的index.php

include('class.phpmailer.php'); // Retrieve the email template required

$message = file_get_contents('mail_templates/sample_mail.html');

$message = str_replace('%testusername%', $username, $message);

$message = str_replace('%testpassword%', $password, $message);

$mail = new PHPMailer(); $mail->IsSMTP(); // This is the SMTP mail server

$mail->SMTPSecure = 'tls';

$mail->Host = "smtp.gmail.com";

$mail->Port = 587;

$mail->SMTPAuth = true;

$mail->Username = 'mygmailid@gmail.com';

$mail->Password = 'mypassword';

$mail->SetFrom('fromgmail@gmail.com', 'Pricol Technologies');

$mail->AddAddress('addaddress@gmail.com');

$mail->Subject = 'Your account information';

$mail->MsgHTML($message);

$mail->IsHTML(true);

$mail->CharSet="utf-8";

//$mail->AltBody(strip_tags($message));

if(!$mail->Send()) {

echo "Mailer Error: " . $mail->ErrorInfo;

}

?>

mail_templates / sample_mail.html

Account Details

Thank you for registering on our site, your account details are as follows:

Username: %username%

Password: %password%

我收到邮件如下:

Account Details

Thank you for registering on our site, your account details are as follows:

Username: %testusername%

Password: %testpassword%

预期产量

Account Details

Thank you for registering on our site, your account details are as follows:

Username: testusername

Password: testpassword

我哪里错了我已经检查过一些论坛.但没有用.

我以前问过一些问题.但是我的项目要求是使用%变量名%的HTML模板,以便任何人都可以在html文件中进行更改,而不用触摸代码部分.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值