Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add HTML formatting in phpmailer

Tags:

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();
like image 287
TheLettuceMaster Avatar asked Dec 09 '12 17:12

TheLettuceMaster


Video Answer


1 Answers

In PHP mailer, you need to set below

$mail->IsHTML(true);

Note: $mail means your PHPMailer object.

Reference Link: PHPMailer

like image 179
GBD Avatar answered Sep 19 '22 17:09

GBD