Forum Moderators: coopster

Message Too Old, No Replies

PHP Form mail -how to HTML format

         

tcady

6:55 pm on Oct 29, 2004 (gmt 0)

10+ Year Member



I am new to PHP, but I am an advanced Javascript programmer so I was able to edit a standard PHP form response script quickly and am moving right along.
When someone fills out my forms I get a nice email of the data.

What I want to know now is how can I now format that email to be HTML (especially tables)?

I tried adding lines like this to my message
"<bold>LITERATURE REQUEST FORM SUBMISSION from navco.org<bold>\n\n" .

and also added this in the variables
$mime_type = "text/html";

but my email comes as text, witht he line looking like this:
<bold>LITERATURE REQUEST FORM SUBMISSION from navco.org<bold>

Also - can my PHP page have instructions to send two differetn emails - one to me, and another to the submitter (each email would have different contentand formattin) - or can I somehow tell a form to submit to two different PHP files - each sending thier own emails....

Thanks!

dmorison

7:00 pm on Oct 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check msg #2 in [webmasterworld.com...] - specifically look at how the $headers parameter is prepared prior to calling the PHP mail() function.

coopster

7:13 pm on Oct 29, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, tcady.

As suggested, the PHP manual pages regarding mail [php.net] and the mail() [php.net] function will come in quite handy. There is also a nice tutorial [zend.com] in there from Zend that you may choose to read.

Timotheos

7:20 pm on Oct 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just to expand on coopster's links look at example #4 on the mail() function page.

tcady

7:50 pm on Oct 29, 2004 (gmt 0)

10+ Year Member



dmorison, thanks it appears to be working great -
next question,

I want the email i get to only have a line break if there is data in a field I write to the email.

For example my form has many rows each with a quantity field...in the email I get, I want the results to be written each on a new line but only if the field had a value:

Item 1 Quantity=34
Item 4 Quantity=7
Item 9 Quanity=2

dmorison

7:07 am on Oct 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want the email i get to only have a line break if there is data in a field I write to the email.

This should just be a case of inspecting the value for each submitted form item before incorporating it into your email. For example, here is a very generic loop that will create an email message body for every item within an HTTP POST, but only if the item has a value:

$message = "";

foreach($_POST as $key => $value) {
if ($value) {
$message .= $key . " = " . $value . "\n";
}
}

... then email $message as normal.