NYCPHP Meetup

NYPHP.org

[nycphp-talk] mail problems

Kenneth Dombrowski kenneth at ylayali.net
Tue Mar 27 19:28:17 EDT 2007


Hi Michael, 

On 07-03-27 17:35 -0500, Michael Southwell wrote:
> It seems to work sometimes and not at other times. My (unhappy) client
> is seeing headers when she gets anything. Multiple recipients seem to
> handled randomly. What can you see here that's wrong? I have tested
> $addresses and it is the properly comma-delimited string.

Have you tried sending the headers and body separately? 

mail($to, $subject, $body, $headers); 

I've never seen anyone do it your way before

> $headers .= "MIME-Version: 1.0\n";
> $headers .= "Content-Type: text/html; charset=ISO-8859-1\n\n";
> $headers .= '
>          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 
> Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

I always send html as part of a multipart message :  

$mime_bound_1 = '__=MIME_BOUND_1=' . md5($_SERVER['HTTP_HOST'] . time());         
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: multipart/alternative; boundary=\"$mime_bound_1\"\n";

and then within your message body each type is delimited by your
$mime_bound_1 ("simpler" content types before more complicated ones): 

$body .= $mime_bound_1 . "\n"; 
$body .= "Content-type: text/plain; charset=\"iso-8859-1\"\n"; 
$body .= "\n"; 
$body .= $your_text_part; 
$body .= "\n"; 

$body .= $mime_bound_1 . "\n"; 
$body .= "Content-type: text/html; charset=\"iso-8859-1\"\n"; 
$body .= "\n"; 
$body .= $your_html_part_including_doctype_and_head; 
$body .= "\n"; 

$body .= $mime_bound_1 . "\n"; 


to generate a text part quickly, I do something like this in my mail
class (if only an html part is set) : 

$tmp = tmpfile(); 
fwrite($tmp, $html_part); 
$elinks = (defined('ELINKS_PATH')) ? ELINKS_PATH : 'elinks'; 
$text_part = `$elinks --dump $tmp`; 
fclose($tmp); 

hth, 
Kenneth 




More information about the talk mailing list