Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Email form and redirect back to the site

Email form and redirect back to the site

12:12 pm on Dec 22, 2011 (gmt 0)

New User

5+ Year Member

joined:Dec 20, 2011
posts: 8
votes: 0

hi i'm a newbie on php and i want to create a for that will collect the name and contact number of the person and send it to my email.

can anyone help me on this?
i've tried this code but doesn't send email to my email account
<?php if(isset($_POST['submit'])) {
$to = "myemail@sample.com"; $name = $_POST['name']; $contact = $_POST['contactl']; $body = "From: $name\n E-Mail: $contact; echo "Data has been submitted to $to!"; mail($to, $body);} else { echo "error!";} ?>can you help me on this?

5:10 pm on Dec 22, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
votes: 0

It's possibly because you're missing a from, which goes in the headers (usually composed as the variable $headers,) and many systems won't send mail without a valid from email. Also the second parameter is subject, you have $body in it. Try one of the examples in the documentation [php.net].