【发布时间】:2015-03-19 03:49:58
【问题描述】:
我使用 swift mailer ,当我从服务器收到一封电子邮件时,我得到了这个:
您通过忘记密码请求您的密码
您的用户名是:{myusername}
您的密码是:{mypassword}
使用 { } ,发送的功能是:
function format_emailforget($info, $format){
//set the root
$root = $_SERVER['DOCUMENT_ROOT'].'/email';
//grab the template content
$template = file_get_contents($root.'/forget_template.'.$format);
//replace all the tags
$template = preg_replace('{USERNAME}', $info['username'], $template);
$template = preg_replace('{EMAIL}', $info['email'], $template);
$template = preg_replace('{PASSWORD}', $info['password'], $template);
$template = preg_replace('{SITEPATH}','http://smracer.com', $template);
//return the html of the template
return $template;
}
这段代码哪里不好?
【问题讨论】:
-
一方面,您没有使用
preg_replace对。模式需要分隔符,{/}是特殊字符。请参阅文档以获取示例,或者,由于您的模板语言非常简单,因此只需使用str_replace代替。 -
谢谢 ceejayoz ,我替换了它,并且没有 {}
标签: php email swiftmailer