-1

希望有人可以帮助解决这个问题。我收到一个PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /site/folder/path/test/send_email.php 在以下代码的第 9 行:

$email_to =   'email@address.com <script type="text/javascript">
/* <![CDATA[ */
(function(){try{vars,a,i,j,r,c,l=document.getElementById("__cf_email__");a=l.className;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>'; //the address to which the email will be sent
$name     =   $_POST['name'];
$email    =   $_POST['email'];
$subject  =   $_POST['subject'];
$message  =   $_POST['message'];

$headers  = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";

if(mail($email_to, $subject, $message, $headers)){
    echo 'sent'; // we are sending this text to the ajax request telling it that the   mail is sent..
}else{
    echo 'failed';// ... or this one to tell it that it wasn't sent
}
4

2 回答 2

2

分隔这些位:

className;if(a){s=\'\';

你用单引号开始字符串:

$email_to =   '...

因此,您需要如上所述在字符串中分隔任何其他单引号。

编辑:我将代码缩进如下:

<?php

$email_to =   'email@address.com <script type="text/javascript">
/* <![CDATA[ */
(function()
{try
    {
            vars,a,i,j,r,c,l=document.getElementById("__cf_email__");
            a=l.className;
            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>';

echo 'Something';
?>

而且我看不到任何解析错误。

于 2012-08-13T11:50:19.503 回答
1

您需要转义单引号\'

$email_to =   'email@address.com <script type="text/javascript">
/* <![CDATA[ */
(function(){try{vars,a,i,j,r,c,l=document.getElementById("__cf_email__");a=l.className;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.pare    ntNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
</script>'; //the address to which the email will be sent
于 2012-08-13T11:50:33.857 回答