我只是在测试我通过Mandrill发送的电子邮件,发现我无法点击任何内容链接。当我使用浏览器的inspect元素时,我发现的是:
public static class StringBuilderSearching
{
public static bool Contains(this StringBuilder haystack, string needle)
{
return haystack.IndexOf(needle) != -1;
}
public static int IndexOf(this StringBuilder haystack, string needle)
{
if(haystack == null || needle == null)
throw new ArgumentNullException();
if(needle.Length == 0)
return 0;//empty strings are everywhere!
if(needle.Length == 1)//can't beat just spinning through for it
{
char c = needle[0];
for(int idx = 0; idx != haystack.Length; ++idx)
if(haystack[idx] == c)
return idx;
return -1;
}
int m = 0;
int i = 0;
int[] T = KMPTable(needle);
while(m + i < haystack.Length)
{
if(needle[i] == haystack[m + i])
{
if(i == needle.Length - 1)
return m == needle.Length ? -1 : m;//match -1 = failure to find conventional in .NET
++i;
}
else
{
m = m + i - T[i];
i = T[i] > -1 ? T[i] : 0;
}
}
return -1;
}
private static int[] KMPTable(string sought)
{
int[] table = new int[sought.Length];
int pos = 2;
int cnd = 0;
table[0] = -1;
table[1] = 0;
while(pos < table.Length)
if(sought[pos - 1] == sought[cnd])
table[pos++] = ++cnd;
else if(cnd > 0)
cnd = table[cnd];
else
table[pos++] = 0;
return table;
}
}
而不是
<a>Test</a>
这是来自Mandrill的API日志:
<a href = "http://test.com">Test</a>
我在上面的API日志中发现可疑的是:它在真实链接之前和之后有3个正斜杠。我查看了其他工作模板的API日志,它们在真实链接之前和之后只有单个正斜杠。所以看起来应该是这样的:
{
"template_name": "Test_Email",
"template_content": [
{
"name": "email-content",
"content": "<a href=\\\"http://test.com/\\\">Test</a>"
}
...
知道这里发生了什么吗?
这是我的PHP代码:
"content": "<a href=\"http://test.com/\">Test</a>"
答案 0 :(得分:1)
答案是使用PHP的stripslashes()函数包装已发布的变量。
stripslashes( $_POST['mass_email_content'] );