Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send PHP mail when user clicks 'Submit'?

Status
Not open for further replies.

elemental

Programmer
Mar 17, 2001
33
0
0
CA
Hey gang! I've got a question.... Made a for for customers to fill in. They hit send and I use the onSubmit behaviour in DWMX to send the stuff they fill in to an address. How cna I use the php mail function. I want when they hit the submit button to get the text entered in the form and send it to their email. How can I do this?
Thanks
Erik
 
you have your form go to another page- on that page you capture the data from the input names
like so
(this page is one I use to capture checkboxes and put them into the email- just remove that)

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
<title>Email</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<?php
$firstname=trim($firstname);
$lastname=trim($lastname);
$email=trim($email);
$phone=trim($phone);
if (empty($firstname))
{
echo &quot;Please go back and enter your first name, this is a required feild&quot;;
exit;
}
if (empty($lastname))
{
echo &quot;Please go back and enter your last name, this is a required feild&quot;;
exit;
}
if (!eregi(&quot;^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$&quot;, $email))
{
echo &quot;You have entered an invalid email address. Please return to the previous page and try again.&quot;;
exit;
}
$toaddress = &quot;contact@domain.com&quot;;
$from = &quot;this@domain.com&quot;;
$mailcontent = &quot;Customer name: &quot;.$firstname . $lastname.&quot;\n&quot;
.&quot;Customer email: &quot;.$email.&quot;\n&quot;
.&quot;Customers order: &quot;. implode(&quot;, &quot;,$_POST['books']) . &quot;\r\n&quot;;

mail($toaddress, $mailcontent, $from);
?>

</head>

<body>
Thank you, your mail has been sent.
</body>
</html>
Sometimes, when my code just won't behave, I take it outside and make it listen to britney spears music, and when it comes back it's really well behaved. I wonder if it's suffering from post tramatic stress syndrome now..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top