[thelist] Double Emails continued in PHP

Seb Potter seb at poked.org
Thu Jul 17 17:24:01 CDT 2003


> $contactemail = "rob.smith at thermon.com";
>
> $message = "<html><head><title></title>";
> $message.= "<meta http-equiv='Content-Type' content='text/html' "; 
> $message.= " charset=iso-8859-1'></head>";
> $message.= "<body bgcolor='#FFFFFF' text='#000000'>";
> $message.= "This is a test from a fellow evolter.";
> $message.= "</body></html>";
>
> $subject = "Evolt PHP Mail Test";
> $headers = "MIME-Version: 1.0\r\n";
> $headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
> $headers.= "From: ".$myname."<".$myemail.">\r\n";
> $headers.= "To: ".$contactname."<".$contactemail.">\r\n";
>
> mail($contactemail, $subject, $message, $headers);
> ?>

Erm, this is dead easy:

the mail function is

mail( to, subject, body, extraheaders )

So, you've already got one recipient with your call:

mail( $contactemail, ... )

but then you've also added a "To:" header in $headers, which you add in 
your call.

So, depending on the way your ISP's MTA is etup, you will either receive 
one or two emails. (Hotmail doesn't de-duplicate multiple To: headers, most 
ISPs do to save traffic and storage.)

Remove the line:

$headers.= "To: ".$contactname."<".$contactemail.">\r\n";

and you're golden.


Oh, btw... \r\n is best practice for portably writing email headers in PHP, 
as although in Linux it will be replaced with a single line-feed, in 
Windows the \r\n is required.


- seb

--
http://poked.org

-- 
http://poked.org


More information about the thelist mailing list