Add HTML formatting in phpmailer

TheLettuceMaster picture TheLettuceMaster · Dec 9, 2012 · Viewed 68.4k times · Source

I am using PHP mailer to send an online form directly to email. I want to edit the form like this:

$message = '<p>The following request was sent from: '</p>;
$message .= '<p>Name: '.$name.'</p><br />';
$message .= '<p>Phone: '.$phone.'</p><br />';
$message .= '<p>Email: '.$email.'</p><br />';

However, in the email I receive back, I get the <p>, <br />, etc. Not the formatting I want, but the actual HTML. It has always worked for me, then I realized I was using the stock PHP mail function. not sure if PHP mailer has different parameters OR if I just missing small here?

Where would I set the headers for text/html?

    $mail = new PHPMailer();
    $mail -> IsSMTP();
    $mail -> Host = "---";
    $mail -> Port = 25;
    $mail -> SMTPAuth = false;
    $mail -> Username = EMAIL_USER;
    $mail -> Password = EMAIL_PASS;
    $mail -> FromName = $from_name;
    $mail -> From = $from;
    $mail -> Subject = $subject;
    $mail -> Body = $message;
    $mail -> AddAddress("---");

    $result = $mail -> Send();

Answer

GBD picture GBD · Dec 9, 2012

In PHP mailer, you need to set below

$mail->IsHTML(true);

Note: $mail means your PHPMailer object.

Reference Link: PHPMailer