Forum Moderators: coopster

Message Too Old, No Replies

Sending an HTML msg with PHP

I need to send an HTML message using PHP mail()

         

teremka

3:29 pm on Aug 26, 2005 (gmt 0)

10+ Year Member



I am having trouble with a PHP mail form. I am using

mail(strTo, strSubject, strMessage);

I would like $strMessage to be in HTML. I have many variables from a form that the user fills in. I don't simply want to list off the values of these variables with no formatting. I would like to put them all in an HTML table that organizes the information in the Inbox. How do I do this?

Thanks!

jatar_k

5:13 pm on Aug 26, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld teremka,

You coould take a look at this thread, though it just uses a text email
Basics of Submitting and Emailing Forms with PHP [webmasterworld.com]

as far as making it html email have you tried just building your html and putting it into your message var?

teremka

5:34 pm on Aug 26, 2005 (gmt 0)

10+ Year Member



Thanks for the welcome. And thanks so much for the help. Unfortunately, the problem I'm having is that instead of formatting the HTML, the email is is literally quoting the HTML (ie: <table><tr><td>) instead of creating a table. But, I think I'm just going to work around it.

Thanks. :)

coopster

2:02 am on Aug 27, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



At least you have the email working. Now, format it and send it with the correct headers for HTML. There is an example on the PHP mail() [php.net] function manual page.

Jaunty Edward

4:51 am on Aug 27, 2005 (gmt 0)

10+ Year Member



Hi teremka,

it seems you know the basics of php so I hope you will be able to make out from this code. Sorry i cant write comments in the code for lack of time:

<?php
$body = "<b>" . $_POST['name'] . "</b>"
$subject = "my first html mail";
$sent = @mail('', $subject, $body,
"To: "Myname<myemail@mydomain.com>\n" .
"From: sender name<sender@gmail.com>\n" .
"MIME-Version: 1.0\n" .
"Content-type: text/html; charset=iso-8859-1");
?>

prepare the body of the mail in $body as

$body = "all html code here";

then you have to take the variables from the form(post or get) and put them into the html code( this is called embedding)

suppose your html code is

$body = "Name: <b> formname </b>";

you want the name from the form to be shown here as bold. So change the $body to:

$body = "Name: <b> " . $_POST['formname'] . "</b>";

embed all the formvariables in the same manner.

Hope this helps

Bye