Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-26-2006, 02:05 PM   PM User | #1
tomyknoker
Regular Coder

 
Join Date: Mar 2006
Posts: 459
Thanks: 3
Thanked 0 Times in 0 Posts
tomyknoker is an unknown quantity at this point
Using PHP To Email A Form

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?
Attached Files
File Type: zip test_form.zip (1.0 KB, 86 views)
tomyknoker is offline   Reply With Quote
Old 10-26-2006, 03:38 PM   PM User | #2
CodilX
New Coder

 
Join Date: Jun 2006
Location: eth0
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
CodilX is an unknown quantity at this point
Code:
<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 Code:
<?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!";

}
?>
__________________
<? print("Hello World") ?>
CodilX is offline   Reply With Quote
Old 10-26-2006, 11:26 PM   PM User | #3
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
Better off using an if statement to check if mail was sent
PHP Code:

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 
__________________
Get Firefox Now
rafiki is offline   Reply With Quote
Old 10-27-2006, 12:37 AM   PM User | #4
tomyknoker
Regular Coder

 
Join Date: Mar 2006
Posts: 459
Thanks: 3
Thanked 0 Times in 0 Posts
tomyknoker is an unknown quantity at this point
Quote:
Originally Posted by rafiki View Post
Better off using an if statement to check if mail was sent
PHP Code:

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
tomyknoker is offline   Reply With Quote
Old 10-27-2006, 08:31 PM   PM User | #5
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
Code:
<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 Code:
<?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  

?>
__________________
Get Firefox Now
rafiki is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:50 PM.


Advertisement
Log in to turn off these ads.