Page 1 of 1
Sending php mail with html
Posted: Fri Jul 13, 2007 12:54 am
by truepal20032001
How can i send a mail as html format if the instance is this:
Code: Select all
<?php
$msg = "<a href=\"http//myurl\">URL</a>";
mail('mymail','sub',$msg,'FROM:'. 'Someone');
?>
i want it to look like this
URL
but it looks like this
Posted: Fri Jul 13, 2007 1:02 am
by GuitarheadCA
You need to create an email with a MIME header; you cannot just use the mail() function. PEAR has a Mime_Mailer class that can be downloaded and implemented for the purpose. It's a lot more work than a plain text email, but I know of no way around it.
Posted: Fri Jul 13, 2007 1:04 am
by truepal20032001
can you show me with some code
Posted: Fri Jul 13, 2007 1:18 am
by GuitarheadCA
I'm not sure how familiar you are with Object Oriented Programming (all of the following depends on it), but it's never too early to learn....
The files/classes you need are available from download on PEAR here <
http://pear.php.net/package/Mail_Mime/download>
You'll also need the base PEAR class available for download here <
http://pear.php.net/package/PEAR/download>
Expand the tarballs, and line up the directories where you need them.
Inside the Mail_Mime directory is an example file, it shows you how to create the email. You access the functions with syntax such as
$mail->setHTML('your string of <strong>HTML</strong> here');
Once you get to that file, it is a little clearer, but it may just take some messing around. I definately think PHP should ship with a way to handle rich-text email internally.
I apologize that this is not simpler, I can't think of any other way to explain it apart from posting 10 pages of code.
Posted: Fri Jul 13, 2007 1:29 am
by truepal20032001
couldn't you just use some headers?...
Code: Select all
$headers = "from: $x_email_from\n";
$headers .= "Content-Type: text/html; charset=us-ascii\n";
$headers .= "Content-Transfer-Encoding: 7bit";
or something like that?...
Posted: Fri Jul 13, 2007 2:36 am
by truepal20032001
yea, sorry... tried it out myself and it was simple 3 lines of code...

Posted: Fri Jul 13, 2007 10:05 am
by GuitarheadCA
Well screw the PHP cookbook, it taught me the long way to do it
