开发者

Unpredictable behavior in PHP-generated email

This is more of a curiosity than anything. The comment system on my site automatically generates an email to me whenever a comment is posted. In it is a link to approve the comment, and a link to deny the comment.

$my_headers = 'MIME-Version: 1.0' . "\n"; 

$my_headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n"; 

$my_headers .= 'From: MYSITE.com <ealert@mysite.com>' . "\n"; 

    $subject = "Comment Received";

    $messagei = "Comment from " . addslashes($_POST['commentName']) ." on ".addslashes($title)."." . "<br /><br />" .addslashes($commentCommment);

    $messagei .= "<br /><br />
        <strong>OPTIONS:</strong>

    <br /><br /><a href='http://www.MYSITE.com/edit/instaprove.php?Approve=Approve&commentid=".$lastID."'>

    <h2>http://www.MYSITE.com/edit/instapr开发者_如何学Pythonove.php?Approve=Approve&commentid=".$lastID."</h2> (Approve Comment)</a>

    <br /><br /><br /><a href='http://www.MYSITE.com/edit/instaprove.php?Remove=Remove&commentid=".$lastID."'>

    <h2>http://www.MYSITE.com/edit/instaprove.php?Remove=Remove&commentid=".$lastID."</h2> (Delete Comment)</a>";

    mail('comments@mysite.com',$subject,$messagei,$my_headers,"-fealert@mysite.com");

99% of the time it works just fine, but every once in a while, instead of generating the approval link correctly, as in

http://www.mysite.com/edit/instaprove.php?Approve=Approve&commentid=142631,

it generates it with a space in it, so the link I get in the email goes to

http://www.mysite.com/edit/instaprove.ph%20p?Approve=Approve&commentid=142631

Strange, no?

Edit: For clarification - When this happens, the link is written out in the email correctly (.php), but the link it goes to is broken (.ph p).

Edit 8/12: It just happened again. The link text is correct:

http://www.mysite.com/edit/instaprove.php?Approve=Approve&commentid=142858

but the link renders as

http://www.mysite.com/edit/%20instaprove.php?Approve=Approve&commentid=142858

So, when it does show up, the mystery space is showing up at different points in the link.


I had a similar problem with spaces and also strange "!\n" appearing in the source of my email.

This was because of very long lines. Adding some "\n" in the content of the email solve the problem.


This is pretty strange.. You may want to just do a string replace on the URL itself replace any whitespace with no characters since it apparently sometimes grabs a random whitespace somehow.

str_replace(" ", "", "http://www.MYSITE.com/edit/instaprove.php?Approve=Approve&commentid=12304728")

It is a pretty strange problem.

My only other option in thought would be to change the charset to UTF-8

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜