Lahiru Chathuranga
Lahiru Chathuranga

Reputation: 151

How to format my email php mailer

When I send the email with html tags.Gmail shows the tags also.Why is that? any solution?how to ad images bold text colored text according to my code? here is my email content code

 smtpmailer("$email", '[email protected]', '<html><body>website.lk Password recovery', 'Password recovery','Dear "'.$name."\"\n\nUse your new password to login and reset your password as you wish.\nTo reset password go to your \"My Account\" page and click \"Change my password\"\n\n"."Here is your new password:\n\n"."Password: "."$password"."\n\nBack to get bump: www.website.lk\n\nRegards,\n website.lk Admin\n</body></html>");

$reset_msg="Recovery completed. Check your e-mail !";       
}else{
$reset_msg="Error in sending email.Try again !";

}

Upvotes: 1

Views: 5217

Answers (3)

Aryan Kasyap
Aryan Kasyap

Reputation: 1

Use $mail->IsHTML(ture); If on phpmailer..

Upvotes: 0

FirmView
FirmView

Reputation: 3150

By including the below headers

    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


    $headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
    $headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
    $headers .= 'Cc: [email protected]' . "\r\n";
    $headers .= 'Bcc: [email protected]' . "\r\n";


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

Source,

http://php.net/manual/en/function.mail.php

if you are using PHP Mailer,

$mail->MsgHTML($body);

$mail->AddAttachment("images/image1.gif");      
$mail->AddAttachment("images/image2.gif"); 

Upvotes: 2

Night2
Night2

Reputation: 1153

if you are using this function:

function smtpmailer($to, $from, $from_name, $subject, $body) { 
    global $error;
    $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;  // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 465; 
    $mail->Username = GUSER;  
    $mail->Password = GPWD;           
    $mail->SetFrom($from, $from_name);
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AddAddress($to);
    if(!$mail->Send()) {
        $error = 'Mail error: '.$mail->ErrorInfo; 
        return false;
    } else {
        $error = 'Message sent!';
        return true;
    }
}

Then change the line of $mail->Body = $body; to code blow:

$mail->MsgHTML($body);

This change will allow you to send HTML emails via PHPMailer, You can also add $mail->CharSet = 'UTF-8'; to avoid future problems with special characters ...

Upvotes: 0

Related Questions