Unpredictable email behavior generated by PHP

This is more of a curiosity than anything. The comment system on my site automatically generates an email to me whenever a comment is sent. It has a link to approve the comment, and a link to reject 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/instaprove.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 when 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 that I get in the email is sent

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

Strange, no?

Edit: for clarification. When this happens, the link is correctly written in the letter ( .php ), but the link to which it goes is broken ( .ph p ).

Edit 8/12: This happened again. Link text is correct:

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

but the link appears as

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

So, when it appears, a secret space appears at different points of the link.

+4
source share
2 answers

I had a similar problem with spaces, as well as the weird "! \ N" appearing in the source of my letter.

This was due to very long lines. Adding some "\ n" to the email content solves the problem.

+6
source

This is pretty weird. You might want to simply replace the string on the URL itself, replacing any spaces without characters, since it seems to sometimes capture random spaces somehow.

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

This is a rather strange problem.

My only other consideration is to change the encoding to UTF-8

+1
source

All Articles