-1

誰かがこの問題について助けてくれることを願っています。次のコードの9 行目に、PHP 解析エラー: 構文エラー、予期しない T_CONSTANT_ENCAPSED_STRING in /site/folder/path/test/send_email.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>'; //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 に答える