Page 1 of 1

PHP and MIME

Posted: Mon Aug 10, 2009 4:39 pm
by jcfox412
Hey all,

I'm trying to put an html tag (namely <a href>) into an email that is being generated with the mail function. As I understand it, I will have to use MIME to do this, as the mail function only outputs plaintext. I would like to have the word "here" in the message link to another php page that displays my database. What is exactly the best way to go about this? Thanks for the help.

Note: $to and $subject are defined above the code that I'm quoting.

Code: Select all

$message = "A new allocation request has been filled out.  You can review the request here.";
$headers .= 'MIME-Version: 1.0' . "\r\n";
 
if(mail($to, $subject, $message, $headers))
{
    echo "Mail sent successfully." ;
}
else
{   
    echo "An error occurred, and your mail was not sent. Please try again later.";
}
 
 
 

Re: PHP and MIME

Posted: Mon Aug 10, 2009 9:24 pm
by yacahuma
use swiftmailer

Re: PHP and MIME

Posted: Tue Aug 11, 2009 2:51 pm
by izzy4505
What you are about to do is very complicated on the back-end of things. To make it simple, use the PEAR Mail and MIME classes.

http://forums.codewalkers.com/pear-pack ... -4748.html

The code at the top of that page is a great way to get started, and it's super easy from there. setHTMLBody() is what you want. Ignore the parts about file attachments.

You should always send a plain text version of the e-mails you send HTML formatted. Not everybody out there has an e-mail client capable of displaying HTML, and many more have these options disabled. Without the plain-text version as well, the folks reading your e-mail will either see nothing at all, or a big pile of random characters.

Re: PHP and MIME

Posted: Tue Aug 11, 2009 6:24 pm
by yacahuma
swiftmailer is equally simple. Is up to you.