Form data to email

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
trevor_o@shaw.ca

Form data to email

Post by trevor_o@shaw.ca »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I hope someone can help.  I'm pretty new to PHP, but I have a form that first inserts values in a mySQL db, and then emails the webmaster with the form contents.

Code: Select all

$email = $HTTP_POST_VARS[email];
$mailto = "yourname@host.ca";
$mailsubj = "Form submission";
$mailhead = "From: Smartmouth";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form:\n";

while (list ($key, $val) = each ($HTTP_POST_VARS)) { 

         //if(!eregi($key,"submit");

$mailbody .= "$key : $val\n\n"; }

if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }
The problem is I don't want the email to display all of the fields in the form. This code loops through everything and spits it all out.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

You are using a pretty old bit of code.

Code: Select all

$email=$_POST['email'];
is more up to date.

It also gives the clue to grabbing the values you want...

Code: Select all

$wantedfield=$_POST['wantedfield'];
Then append to your mailbody

Code: Select all

$mailbody.='Wanted field: '.$wantedfield.'\n';
Give it a go and then come back!
Post Reply