visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: php mail() disaster


By: FlorenceYee U.S.A.  Date: 29/06/2003 00:00:00  English  Points: 300 Status: Answered
Quality : Excellent
I'm new to PHP so please help me:

<?
$myboundary = "_Boundary--_". md5(rand()) ."";
$headers .= "Content-Type: multipart/alternative; boundary=\"$myboundary\"\n";
$headers .= "From: webmaster@myweb.com\n";
$headers .= "Date: " . date("r") . "\n";
$headers .= "--$myboundary\n";
$headers .= "Content-Type: text/html; charset=\"utf-8\"\n";
$headers .= "Content-Transfer-Encoding: quoted-printable\n";
if(mail($rcpt,$Subject,"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n".stripslashes($myBody)."\n--$myboundary--",$headers)){
Header ("HTTP 302 Redirect");
Header ("Location: " . "<A HREF="http://myweb.com">http://myweb.com</a>");
};
?>

I couldn't even send good HTML messages without it getting crippled. Most " are turned into \" and sometimes even =" are thrown away. I've most problem with Iplanet messaging servers. they even replace the boundaries with their own. Help anyone! how do i preserve a pure HTML for my messages?
By: ThG Date: 29/06/2003 03:03:00 English  Type : Assist

I can't understand from only that code what exactly is going on, but i can give you two tips that will surely help:

1) before taking any parameter from $_GET or $_POST (or if you have register_globals ON, from the parameter variable) without passing it thru stripslashes(), and BEFORE using it for concatenating with some html tags..

2) pass all the data you are inserting thru htmlentities(), again before concatenating with html tags.

i hope this helps
By: VGR Date: 29/06/2003 04:45:00 English  Type : Answer
1) $headers .= "--$myboundary\n";

is wrong

the boundary is in the BODY only

in the headers, it should read like :

$headers.="Content-Type: multipart/mixed; boundary=\"--$myboundary\"\r\n";

2) don't forget ALSO that the OFFICIAL separator in headers is \r\n, NOT \n alone

3) don't forget also that you need a blank line before the body starts

By: FlorenceYee Date: 29/06/2003 16:13:00 English  Type : Comment
another problem is i'm transfering $myBody from another website running ASP.Net. All the characters seemed to be HTML encoded when php mail() sends it out. Do i have to encode the HTML before POST or what?

Do register to be able to answer

EContact
browser fav
page generated in 336.525920 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page