...

View Full Version : Using PHP To Email A Form



tomyknoker
10-26-2006, 03:05 PM
I am wondering if I can use PHP to email the following form? And does anyone have any examples, or can anyone work with this example?

CodilX
10-26-2006, 04:38 PM
<form method="POST" action="mailer2.php">
Name:
<input type="text" name="name" size="19"><br>
<br>
E-Mail:
<input type="text" name="email" size="19"><br>
<br>

<input type="checkbox" name="check[]" value="blue_color"> Blue<br>
<input type="checkbox" name="check[]" value="green_color"> Green<br>
<input type="checkbox" name="check[]" value="orange_color"> Orange<br>
<br>
Message:<br>
<textarea rows="9" name="message" cols="30"></textarea><br>
<br>
<input type="submit" value="Submit" name="submit">
</form>


<?php
if(isset($_POST['submit'])) {


$to = "mail@mail.com";
$subject = "Form";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

foreach($_POST['check'] as $value) {

$check_msg .= "Checked: $value\n";

}

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n $check_msg";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);


} else {

echo "blarg!";

}
?>

rafiki
10-27-2006, 12:26 AM
Better off using an if statement to check if mail was sent



if (mail($to, $subject, $message)) //if the mails sent
{ header(Location : "http://www.server.com/thanks.html");
}
//page to redirect to if your email was sent
else
{ echo "Sorry. Error sending message!";} //show that email could not be sent

tomyknoker
10-27-2006, 01:37 AM
Better off using an if statement to check if mail was sent



if (mail($to, $subject, $message)) //if the mails sent
{ header(Location : "http://www.server.com/thanks.html");
}
//page to redirect to if your email was sent
else
{ echo "Sorry. Error sending message!";} //show that email could not be sent
So how do I put it all together? Sorry I'm a newbie and still get confused :confused:

rafiki
10-27-2006, 09:31 PM
<form method="POST" action="mailer2.php">
Name:
<input type="text" name="name" size="19"><br>
<br>
E-Mail:
<input type="text" name="email" size="19"><br>
<br>

<input type="checkbox" name="check[]" value="blue_color"> Blue<br>
<input type="checkbox" name="check[]" value="green_color"> Green<br>
<input type="checkbox" name="check[]" value="orange_color"> Orange<br>
<br>
Message:<br>
<textarea rows="9" name="message" cols="30"></textarea><br>
<br>
<input type="submit" value="Submit" name="submit">
</form>



<?php
if(isset($_POST['submit'])) {


$to = "mail@mail.com";
$subject = "Form";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

foreach($_POST['check'] as $value) {

$check_msg .= "Checked: $value\n";

}

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n $check_msg";
mail($to, $subject, $body);

if (mail($to, $subject, $body)) //if the mails sent
{ header(Location : "http://www.server.com/thanks.html");
}
//page to redirect to if your email was sent
else
{ echo "Sorry. Error sending message!";} //show that email could not be sent

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum