views:

44

answers:

3

I have created an php mail script, And in the message of the mail i sent i am using many variables (data). For example i want to sent an mail with this body msg:

Name: Somename
Email: [email protected]
City: Somecity
State: somestate
.........

What i am doing is this:

$msg = "Name: $name (brake) Email: $email (brake)......"

this message is not working in major emails like gmail, hotmail, yahoo... I get the mail with html tags and i dont want that.

There must be some other way to do this so my mail structure looks good on every email account ?

+2  A: 

Make sure in the header declarations you are declaring it as an HTML e-mail.

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"

http://php.net/manual/en/function.mail.php should help out as well. Follow the example code in there and it's guaranteed to work.

Mike Keller
A: 

Well there is the possibility that you aren't setting the header to indicate that the type is HTML. But why would you want to roll your own mail sender. There is a great email sender for php: http://sourceforge.net/projects/phpmailer/ and it is free.

spinon
+2  A: 

I would recommend the PHP email packages available through PEAR:

PEAR Mail - for interfacing with the server/smtp mailer and performing the action of sending PEAR Mail_Mime - Which handles the formatting for sending of plaintext or HTML email.

Check out the documentation for usage.

apiri
+1: This is definitively the way to go. Email building is not a trivial matter, especially when dealing with user input (character encoding, escaping, etc.). `Mail_Mime` simplifies all this.
Andrew Moore
Zend_Mail and Swiftmailer are also highly recommended. Creating your own is not worth the trouble.
The Pixel Developer