Tyler Tyler - 1 year ago 76
HTML Question

Using HTML and PHP to send form data to an email

Like the title says, sending a form to my email. I get no errors, but the email never comes. Here's my HTML form (I don't think you'll need anything else, but there is also some formatting and Java verification in the file).

<form method="POST" name="contactform" action="contact-form-handler.php">
<label for='name'>Your Name:</label>
<input type="text" name="name">
<label for='email'>Email Address:</label>
<input type="text" name="email">
<label for='message'>Message:</label>
<textarea name="message"></textarea>
<input type="submit" value="Submit">

And here's my PHP. Obviously I took my email out and put in EMAIL instead, but other than that this is my complete PHP file. The thank you PHP file pulls up the submitted page just fine, and I get no errors. Just no email either.

$errors = '';
$myemail = 'EMAIL@gmail.com';
if(empty($_POST['name']) ||
empty($_POST['email']) ||
$errors .= "\n Error: all fields are required";
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/ ^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$errors .= "\n Error: Invalid email address";
if( empty($errors))
$to = '$myemail';
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email_address\n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');

Thanks ahead of time for any help you can provide! I can give the rest of my HTML file or my other PHP file if you need it, this is where all the real functionality lies though.

Answer Source

*PHP to send form data to an email i have used this code as well as its work for me .you can try *

$email = $_POST["emailaddress"];
$to = "you@youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n

Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: you@youremailaddress.com\n";
$usermessage = "Thank you for subscribing to our mailing list.";

after that you can addded your futher code

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download