我只是在测试我通过Mandrill发送的电子邮件,发现我无法点击任何内容链接。当我使用浏览器的检查元素时,我发现的是:
<a>Test</a>
而不是
<a href = "http://test.com">Test</a>
这是来自Mandrill的API日志:
{
"template_name": "Test_Email",
"template_content": [
{
"name": "email-content",
"content": "<a href='''"http://test.com/'''">Test</a>"
}
...
我在上面的 API 日志上发现可疑的是:它在真实链接之前和之后都有 3 个正斜杠。我检查了其他工作模板的 API 日志,它们在 true 链接之前和之后只有一个正斜杠。所以它应该看起来像这样:
"content": "<a href='"http://test.com/'">Test</a>"
知道这里发生了什么吗?
这是我的PHP代码:
$mandrill = new Mandrill("KEY_CODE");
$message = array(
'subject' => $_POST['mass_email_subject'],
'from_email' => 'noreply@test.com',
'to' => array(
array(
'email' => $user->user_email
)
)
);
$template_name = 'Test_Email';
$template_content = array(
array(
'name' => 'email-content',
'content' => $_POST['mass_email_content'] // '<a href = "http://test.com/">Test</a>'
)
);
$mandrill->messages->sendTemplate( $template_name, $template_content, $message );
答案是用 PHP 的 stripslashes() 函数包装你发布的变量。
stripslashes( $_POST['mass_email_content'] );