PHP and MIME

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jcfox412
Forum Newbie
Posts: 3
Joined: Mon Aug 10, 2009 9:06 am

PHP and MIME

Post 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.";
}
 
 
 
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: PHP and MIME

Post by yacahuma »

use swiftmailer
izzy4505
Forum Newbie
Posts: 16
Joined: Tue Aug 11, 2009 1:38 pm

Re: PHP and MIME

Post 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.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: PHP and MIME

Post by yacahuma »

swiftmailer is equally simple. Is up to you.
Post Reply