SOLVED: How to send a HTML mail

All your question about php
Post Reply
mister_v
Posts: 199
Joined: Thu Mar 04, 2010 9:19 pm

SOLVED: How to send a HTML mail

Post by mister_v »

Hi,

I want to send a HTML-mail.

I know to use the mail-function.
But it only send text, not in HTML format.

Thanks,
Last edited by mister_v on Wed Feb 09, 2011 8:04 pm, edited 1 time in total.
chris
Site Admin
Posts: 205
Joined: Mon Jul 21, 2008 9:52 am

Re: How to send a HTML mail

Post by chris »

With PHP it is easily done.

You create the body of your message in html.
Don't forget <html><body></body></html>

and in the headers you tell it is a HTML-mail with the following line:

Code: Select all

Content-type: text/html\r\n
So the complete code looks something like this:

Code: Select all

$email='someone@somewhere.com';
$subject='This is the Subject;
$headers  = "From: me@here.com\r\n";
$headers .= "Content-type: text/html\r\n";

$body='<html><body><h1>My HTML mail:</h1>and the rest of the mail</body></html>';

mail($email,$subject,$body,$headers);
If you have more questions, just let me know.
Post Reply