SAB206 Posted April 29, 2010 Share Posted April 29, 2010 Hi all, I'm new to the site and PHP for that matter, so please bare with me I've set up a simple 'contact' form, which relays the information via PHP to my email account. However, every time the form gets used, when the email comes through, the "FROM" field comes up with a random generic email address form the domain, as appose to what the person has entered in the 'email' field. hope that makes sense Please help. HTML... <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <form method="POST" action="mailer.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> <input type="radio" value="yes" name="radio"> YES<br> <input type="radio" value="no" name="radio"> NO <br> <br> <select size="1" name="drop_down"> <option>php</option> <option>xml</option> <option>asp</option> <option>jsp</option> </select><br> <br> Message:<br> <textarea rows="9" name="message" cols="30"></textarea><br> <br> <input type="submit" value="Submit" name="submit"> </form> </body> </html> and the PHP for it. <?php if(isset($_POST['submit'])) { $to = "[email protected]"; $subject = "SAB-GRAPHICS MAIL"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; $option = $_POST['radio']; $dropdown = $_POST['drop_down']; foreach($_POST['check'] as $value) { $check_msg .= "Checked: $value\n"; } $body = "From: $name_field\n E-Mail: $email_field\n $check_msg Option: $option\n Drop-Down: $dropdown\n Message:\n $message\n"; echo "Data has been submitted to $to!"; mail($to, $subject, $body, '-f'.$email_field); } else { echo "blarg!"; } ?> Link to comment https://forums.phpfreaks.com/topic/200227-help-on-php-form-to-mail-please/ Share on other sites More sharing options...
ChemicalBliss Posted April 29, 2010 Share Posted April 29, 2010 If you mean the actual body, where you' ve given the details, there is no reason why it would do this. Use print_r($_POST); aat the top of your process script tocheck wether the post vriables arebeing submitted properly. If you mean the actual header of the email then you need to specify the headers of the email with the from, rather than the body. Google: PHP Email Headers For a lot of info on email headers. -cb- Link to comment https://forums.phpfreaks.com/topic/200227-help-on-php-form-to-mail-please/#findComment-1050772 Share on other sites More sharing options...
andrewgauger Posted April 29, 2010 Share Posted April 29, 2010 mail($to, $subject, $body, '-f'.$email_field); should be: mail($to, $subject, $body, "Reply-To: $email_field\r\nFrom: [email protected]\r\n\r\n"); Link to comment https://forums.phpfreaks.com/topic/200227-help-on-php-form-to-mail-please/#findComment-1050778 Share on other sites More sharing options...
otuatail Posted April 29, 2010 Share Posted April 29, 2010 Your mail function is not right and this does happen under these conditions This ... mail($to, $subject, $body, '-f'.$email_field); should be ... mail($to, $subject, $body, 'From: $name_field <$email_field>\r\n'); you need something like 'From: Fred <[email protected]>\r\n' you need the \r\rn & name<email> Desmond Link to comment https://forums.phpfreaks.com/topic/200227-help-on-php-form-to-mail-please/#findComment-1050780 Share on other sites More sharing options...
SAB206 Posted May 3, 2010 Author Share Posted May 3, 2010 Excellent! Cheers people. Sorted it thanks to your sound advice. Thank you for your help, your time was much appreciated. Scott. Link to comment https://forums.phpfreaks.com/topic/200227-help-on-php-form-to-mail-please/#findComment-1052431 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.