SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: PHP Form
-
Jul 31, 2006, 17:07 #1
- Join Date
- Jul 2006
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Form
I have a PHP form that works decently and it captures all the information I want. What I would like it to do is to email the person on the form using the email address that was captured when he/she inputted it. Is this possible?
-
Aug 1, 2006, 03:14 #2
check out the mail function
http://www.php.net/mail
-
Aug 1, 2006, 05:21 #3
-
Aug 1, 2006, 14:53 #4
- Join Date
- Jul 2006
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){
// In testing, if you get an Bad referer error
// comment out or remove the next three lines
if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])>7 ||
!strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']))
die("Bad referer");
$msg="Values submitted by the user:\n";
foreach($_POST as $key => $val){
if (is_array($val)){
$msg.="Item: $key\n";
foreach($val as $v){
$v = stripslashes($v);
$msg.=" $v\n";
}
} else {
$val = stripslashes($val);
$msg.="$key: $val\n";
}
}
$recipient="myemail@domain.com";
$subject="From Website";
error_reporting(0);
if (mail($recipient, $subject, $msg)){
echo "<h1>Thanks</h1><p>Message sent. Please click the back button if you wish to continue browsing the site.</p>\n";
echo nl2br($input);
} else
echo "An error occurred and the message could not be sent.";
} else
echo "Bad request method";
?>
So where would I put that code. Sorry for the ignorance but my php coding skills are next to nothing.
-
Aug 2, 2006, 05:42 #5
- Join Date
- Jun 2003
- Location
- Athens, Greece
- Posts
- 283
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well, that's a good question since your code doesn't exactly spell out what the keys are in your array area.
As it is your code, you should be able to extract which $key => $val you should extract the user's email address from. Then just create another part at the bottom in the if (mail area with the message that you want to send and add another (mail code portion to send it to the user.
Peter
Originally Posted by jiggawhat
-
Aug 2, 2006, 14:05 #6
- Join Date
- Jul 2006
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I got this code from somewhere else and I just modified it. It's supposed to capture each form field and put it in the email and submit it to me.
-
Aug 2, 2006, 18:32 #7
The form on my contact page has four input values:
name
email
subject
message
The following is the confirmation page:
PHP Code:Your message titled "<?php echo "$subject"; ?>" has been sent.
We will contact you as soon as possible. Thank you.</p>
<p align="center" class="style6"><span class="style6"><a href="index.php">Home</a></span></p>
<?
$to = "email@userdomain.com";
$msg = "$name\n\n";
$msg .= "$message\n\n";
mail($to, $subject, $msg, "From: $email\n\nReply-To: $email\n");
?>[\/] [/\\//\]
-
Aug 3, 2006, 07:29 #8
- Join Date
- Jun 2003
- Location
- Athens, Greece
- Posts
- 283
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
So based on what you have written, you want to add this code after the
echo "Bad request method";
code that you already have:
$cc = $_post["email"]; this copies the value of the email address
mail($cc, $subject, $msg,
"From: youremail@yourdomain.tld\n\n
Reply-To: youremail@yourdomain.tld\n");
this will send a copy of what was submitted to the user.
Peter
Originally Posted by PHPmySQLer
Bookmarks