Jump to content

Send SMTP mail with HTML?


StefanRSA

Recommended Posts

I am sending mail from a form using smtp authentication.

When I use HTML in my message, It ignores my HTML tags and print them out in the email....

 

My Mail script works as follow:

include("Mail.php");
/* mail setup recipients, subject etc */
$headers["From"] = "[email protected]";
$headers["To"] = $frmail;
$headers["Subject"] = "The mail subject";
$headers["Reply-To"] = $replyemail;
$mailmsg = "Message for mail goes here. \n
            <a href='http://www.domain.com'>CLICK HERE</a> \n
            Greetings from Domain";
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "mail.domain.com";
$smtpinfo["port"] = "25";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "user+domain.com";
$smtpinfo["password"] = "password";
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$mail_object->send($frmail, $headers, $mailmsg);

 

What must I add to accept HTML in my sent mail?

Link to comment
https://forums.phpfreaks.com/topic/178463-send-smtp-mail-with-html/
Share on other sites

If I use mail() some mail clients mark it as spam... This is the reason for sending with smtp.

My script is working and I don't want to change it to a diff class. I want to know what I should do to allow for HTML in emails sent using SMTP..... Or do I miss anything?

The reason I said use PHPMailer, is because it is so flexible it takes care of all the MIME Boundry strings and allows you to send text only, HTML only text/html emails and there are a lot of other nice features with it.

 

 

This is what needs to go to make it HTML viewable. But the way your passing in the $headers information will make it a little different.

 

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

 

do you have to pass the header information in as array items?

 

You need to determine how to add the mime version and content type to the headers. Those are the key pieces.

 

there is also a mailer type declaration, that I cannot remember off hand how it is setup, but you can google for it.

 

Or you can make a few changes and go with PHPMailer class and be done with it. I fought and fought with emails before I found PHPmailer. Once I figured out how to use it, I have not had mail hit the spam folder, sent HTML mail with a text-only version .... easy peasy

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.