PDA

View Full Version : PHP Mail Form?



telekinesis
October 13th, 2003, 06:20 PM
I am simply looking for a tutorial on how to make an HTML (or flash) form where the user can select options from either check boxes, radio boxes, or drop downs. The user then submits information like his email and other comments and then they press submit. Then it is sent to my email. Using PHP.

Any help will be greatly appreciated.

ratbaggy
October 13th, 2003, 06:40 PM
http://codewalkers.com/tutorials.php?show=10

HTH

Voetsjoeba
October 14th, 2003, 02:08 PM
I've done something very similar in the past for asianillusion.com. If you want it, I can send it to you :)

Not2Sure
October 14th, 2003, 02:29 PM
since kirupa still have not posted my tut on this i will help

change the first 5 lines.

save this as mailer.php


<?PHP
$to = "ADD YOUR EMAIL HERE";
$subject = "Results from your Request Info form";
$headers = "From: Form Mailer";
$forward = 0;
$location = "";

$date = date ("l, F jS, Y");
$time = date ("h:i A");



$msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n\n";

if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}

mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting our form. We will get back to you as soon as possible.";
}

?>

now add this as the HTML form.


<form action="mailer.php" method="post"> </form>

PHP exaplined

$to = "me@this.com";
Change "me@this.com" to your email. (you must keep the "" marks)

$subject = "Results from your Request Info form";
This will be the subject of the Email when it is sent

$headers = "From: My Site";
This will be who it is from, usally My site or something like that.

$forward = 0;
redirect? 1=yes 0=no (this is the page you go to after you submit the form. if left on 0 you will see a message then nothing will happen if you select 1 you will see a meaage then go to the redirect page.)

$location = "yoursite.com";
This will be the page you are redirected. (if you keep it 0 you do not need one just delete "yoursite.com"; and leave ""; instead)

now you can add as many elements to the form with NO change needed to the PHP code EVER. just add the "name="name"> app in each element.

example

<input type="text" name="text">

andrthad
October 15th, 2003, 11:02 AM
Hey Voets,

Would you please send it my way as well.

prstudio
October 15th, 2003, 01:49 PM
wait wait, dan is trying to learn a server language?

*faints

Voetsjoeba
October 15th, 2003, 02:42 PM
andrthad, please remind me somehow, I'll forget otherwise. I know myself.

telekinesis
October 16th, 2003, 07:40 PM
Originally posted by prstudio
wait wait, dan is trying to learn a server language?

*faints :P


Thanks Guys!

ahmed
October 16th, 2003, 07:48 PM
you might as well wanna try this one, :)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

if (isset($_POST['mode'])) {

/* replace this with your own */
$to = "me@mysite.com";

$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];

$mail = mail( $to , $subject , $message , "$name <$email>" );

if ( $mail ) echo 'Message successfully sent';
else echo 'Error sending message';

} else {

echo <<<FORM <form name="form1" method="post" action="index.php">
<input name="mode" type="hidden" value="2">
<table>
<tr>
<td>Name:</td>
<td><input name="name" type="text"></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input name="email" type="text"></td>
</tr>
<tr>
<td>Subject:</td>
<td><input name="subject" type="text"></td>
</tr>
<tr>
<td>Message:</td>
<td><textarea name="message" cols="" rows=""></textarea></td>
</tr>
<td></td>
<td><input type="submit"></td>
</tr>
</table>
FORM;

}

?>
</body>
</html>