我正在尝试在我的网站上设置一个联系人框,我以为我做得对,但似乎没有。
?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "contact@jozhhdesigns.com
<script>
type = "text/javascript" >
/* <![CDATA[ */
(function() {
try {
var s, a, i, j, r, c, l, b = document.getElementsByTagName("script");
l = b[b.length - 1].previousSibling;
a = l.getAttribute('data-cfemail');
if (a) {
s = '';
r = parseInt(a.substr(0, 2), 16);
for ( j = 2; a.length - j; j += 2) {
c = parseInt(a.substr(j, 2), 16) ^ r;
s += String.fromCharCode(c);
}
s = document.createTextNode(s);
l.parentNode.replaceChild(s, l);
}
} catch(e) {
}
})();
/* ]]> */
</script>";
$subject = "JozhhDesigns You have been contacted!";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
然后,我得到的错误是:
第7行代码中的意外T_STRING
有人知道这里出了什么问题吗?
在查看评论后,我改变了一些内容,现在我有了以下内容
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = 'contact@jozhhdesigns.com';
<script type='text/javascript'>
/* <![CDATA[ */
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
</script>
$subject = 'JozhhFX You have been contacted!';
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
有了这个我删除了双(“)并用单(')替换它们 它现在给我错误
"syntax error, unexpected '<' in /public_html/sendmail.php on line 6"
我知道我对此不好但对此有任何帮助吗?
答案 0 :(得分:0)
更改
$recipient = "contact@jozhhdesigns.com
<script>
type="text/javascript">
/* <![CDATA[ */
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
</script>";
到
$recipient = "contact@jozhhdesigns.com";
<script type="text/javascript">
/* <![CDATA[ */
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
</script>
答案 1 :(得分:0)
您使用其外部的类型声明关闭开始脚本标记。
<script <-- Here
type="text/javascript">
答案 2 :(得分:0)
$收件人应该只是电子邮件,试试这个:
$recipient = "contact@jozhhdesigns.com";
这是关于php中的邮件功能的文档:http://php.net/manual/en/function.mail.php
答案 3 :(得分:0)
您的$收件人的值为双引号!
尝试类似
的内容$recipient = "contact@jozhhdesigns.com";
$script = <<<CDATA
<script>
type="text/javascript">
/* <![CDATA[ */
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
</script>
CDATA;
答案 4 :(得分:0)
在这里使用单引号而不是双引号type =“text / javascript”&gt;这里是document.getElementsByTagName(“script”);
有点像这种类型='text / javascript'&gt;和document.getElementsByTagName('script');
答案 5 :(得分:0)
有一些结束标记和双qoutes问题请尝试此
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "contact@jozhhdesigns.com";
$subject = "JozhhDesigns You have been contacted!";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>