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!
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.
$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.";
}
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.