How we can send html page or template in mail in PHP ???

Reply

Join Date: Feb 2009
Posts: 130
Reputation: gagan22 is an unknown quantity at this point 
Solved Threads: 0
gagan22 gagan22 is offline Offline
Junior Poster

How we can send html page or template in mail in PHP ???

 
0
  #1
Aug 7th, 2009
Hi all,

I am working on an application in php. Now my client want that when i will send mail from form then in message there should be some html code or template of html. Please tell me how i can send this through mail of PHP.

Let me explain:
Like we send mail in php like this :
mail($mailto,$subject,$message,"From:$email1");
Now i want that in $message there should be some html code in which i can use color and some links . That should appear in mail after filling form.

So please help me . How i can do this in PHP.
Thanks,
Gagan
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 17
Reputation: omniuni is an unknown quantity at this point 
Solved Threads: 2
omniuni's Avatar
omniuni omniuni is offline Offline
Newbie Poster

Re: How we can send html page or template in mail in PHP ???

 
0
  #2
Aug 7th, 2009
You need to change the headers to define "text/html" instead of the default, which is plain text. (headers are the fourth argument in the mail() function)
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: How we can send html page or template in mail in PHP ???

 
0
  #3
Aug 7th, 2009
You only need the first 2 lines of the headers below, but there's some additional headers in case you wanted to see how to add those as well. Also, make sure to "\r\n" in double quotes, not single quotes, AND they must appear at the end of every line in the headers
  1. // Additional headers
  2. $headers = 'MIME-Version: 1.0' . "\r\n";
  3. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  4.  
  5. $headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
  6. $headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
  7. $headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
  8. $headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
  9.  
  10. mail($to, $subject, $message, $headers);
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 17
Reputation: omniuni is an unknown quantity at this point 
Solved Threads: 2
omniuni's Avatar
omniuni omniuni is offline Offline
Newbie Poster

Re: How we can send html page or template in mail in PHP ???

 
0
  #4
Aug 7th, 2009
Very nice, Paradox. Very clean code. I've had some difficulty with this in the past, I am definitely going to reference this page.

Oh, but in reference to another post I answered, I think UTF-8 may work a bit better.
Last edited by omniuni; Aug 7th, 2009 at 11:19 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: How we can send html page or template in mail in PHP ???

 
1
  #5
Aug 7th, 2009
Your absolutely right omniuni, I would use utf-8 instead.
  1. $headers.= 'Content-Type: text/html; charset=UTF-8' .' "\r\n";
  2.  
Since my site is completely in English, it hasn't made a difference (to me). But in general you never know what countries/languages your visitors will be coming from and this is something you should get right the first time so you never have to worry about it.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 72
Reputation: hireaprogrammer is an unknown quantity at this point 
Solved Threads: 1
hireaprogrammer's Avatar
hireaprogrammer hireaprogrammer is offline Offline
Junior Poster in Training

Re: How we can send html page or template in mail in PHP ???

 
0
  #6
Aug 8th, 2009
Hello, All this code will help you to send mail but in mail if you need same like home page or you want to show image in mail or css or html code with same color then you have to change all the path of image to server page means your images in image floder so your current page will be images/image name Now when you want to show this image into mail then your path will he http://domainname.com/images/image name

Same for CSS and all the path

i hope this will help you ..

Regards
hire-phpdeveloper.com
Start from $3.99 Per Hour
Yahoo IM :hirephpdeveloper
Web Development with php | Hire a dedicated php developer |Hire indian Php developer
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC