Hello, I've been trying to send html emails via the mail() function. I tried different combinations of headers configurations. and spent hours and hours on this with no luck. All I get is plain text, as if i did not define the headers. headers would be displayed in the message as well.

I am pretty sure it is not a matter of correct headers. as i literally tried everything.

Just can figure out what is preventing it from encoding the message as html.

appreciate your help!


Probably the easiest way to go would be to use the mailer from the PEAR package for php, all you do is set isHTML to true and it will write the headers and all that good stuff for you. It makes mail 100 times easier.
Here's the link for you

Thanks shawn,

I managed to get PEAR working on my box. and am sending emails. but I still have the same problem of emails sent without html encoding.

i think its something to do with the settings of Mail. cant find any documentation on html encoding on the PEAR Mail website.

this is my php script:

require 'Mail.php';
$recipients = 'roy@example.com';

$headers['From']    = 'contact@example.net';
$headers['To']      = 'roy@example.com';
$headers['Subject'] = 'Test message';

$body = 'Test <b>message</b>';

//$params['sendmail_path'] = '/usr/sbin/sendmail -t -i';
$params['sendmail_path'] = '/usr/sbin/sendmail';
$params['isHTML'] = 'true';

// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('sendmail', $params);
$mail_object->send($recipients, $headers, $body) or die("could not send email");

and this is the email output:



This is using the PEAR mailer package


// personal info ommitted
$mail = new PHPMailer();
    $mail->From = "Application@NarutoFor.Us";
    $mail->FromName = "NarutoMUD";    
    $mail->Subject = "Thank you for applying to NarutoMUD";
    $replymsg = str_replace("%RESPONSE%", "{$response}", $replymsg);
    $mail->Body = $replymsg;
    $mail->WordWrap = 50;
    $mail->AltBody = $altmsg;
    $mail->IsHTML(true); //note this line
       echo 'Message was not sent.';
       echo 'Mailer error: ' . $mail->ErrorInfo;
Member Avatar


add mimetypes to your code...

add mimetypes to your code...

the PEAR mailer class automatically adds the text/html mimetype to the headers when you say implementation->isHTML = true;

Member Avatar


but the result is still plain text.

I'm not sure what implementation you are using because, obviously, it looks very different from the one I'm using. There wasn't really any "installing" when using the PEAR mailer. It was just downloading the class.phpmailer.php file and using the functions provided.