There\'s a lot of blank php email posts on here but none of them have solved this for me.
I tweaked this simple php code I found to simply email a specified email addres
Why is your form action MAILTO:
?
It should just be a clean call to the PHP page like this:
The only time you would use MAILTO:
is when constructing an . For an HTML form using PHP like this the goal is to submit the form, and the the
$_POST
data gets parsed by the PHP which then acts on it to send an e-mail.
Additionally, you are not setting name
values in any of the input
fields & the names you have for id
values dont even match what the PHP is attempting to do. So try this for the HTML:
Also here is the reworked PHP code.
The first thing I did was take all of your $_POST
checks into a structure that uses one main array ($post_array
) and then rolls through that array to process the values & assign them to similarly named variables. You had absolutely no input validation before. This is technically not even really great “validation” since isset()
just checks to see if the $_POST
value even exists. But this is step up.
Also I reworked your error checking logic at the end since it all happened after headers were sent. Meaning none of that the whole "We've recived your information"
would never work. This is the best I can do with the info you’re providing, but I am doing this to convey the basic concepts:
$post_value) {
$$post_key = isset($_POST[$post_key] ? $_POST[$post_key] : null;
}
// From
$header="from: $name <$mail_from>";
// Enter your email address
$to ='test@gmail.com';
$send_contact=mail($to,$name,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
header("Location: http://wetzelscontracting.com/postcontact.html");
}
else {
echo "ERROR";
}
}
?>