我有以下代码向用户发送验证电子邮件,其中包含一些变量,例如用于验证的用户名和令牌。变量显然会因人而异。但是,我想将此消息单独存储在 PHP include_path 中,以便在需要时可以在其他地方重新使用它。我不想像现在这样对它进行硬编码:
$to = $username;
$subject = 'Account Verification';
$now = date('Y-m-d H:i:s',time());
$message = "
Date sent:$now
Thanks for signing up!
Your account has been created, however we need to verify that this is your email address. Here is your verification token which you should copy and paste on the verification page:
<strong>$token</strong>
Alternatively, click the below link to activate your account:
http://localhost/login/verification.php?username=$username&token=$token
If you did not register with us. You <a href='http://localhost/login/'>can click</a> here to report this to us, or ignore this email.
Thanks,
The LocalHost Team
";
mail($to, $subject, $message);
所以三个问题:
- 如何以仍然可以访问变量的方式将此消息存储为像模板一样?
- 如何将此消息转换为带有 html 标记的精美 HTML 格式的消息?
我可以这样做:
$to = $用户名;$subject = '账户验证'; $now = date('Ymd H:i:s',time()); $message = 包括“verification_template.php”;邮件($to,$subject,$message);