I’m trying to set up a simple contact form. Everything is styled correctly, but when I hit submit it doesn’t take me anywhere, just attempts to open contact.php. I think there’s something missing in the code that actually sends the message out. I’m sure it’s something fairly simple that I’m missing, but this is a little over my head. Any help is appreciated.
<form action="mail.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Company</p> <input type="text" name="company">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="phone">
<p>Message</p><textarea name="message" rows="4" cols="25"></textarea><br />
<input type="submit" value="Submit">
</form>
<?php
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "______@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
$to ='______@gmail.com';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've received your information"
if($send_contact){
echo "We've received your contact information";
}
else {
echo "ERROR";
}
?>
EDIT: I was able to receive an email finally after adding the complete url for mail.php…however none of the information except for the message was included. The sender was listed as Apache…how can I assure that information entered in the forms will be included in the email? Thanks for all the help thus far.
since you are specifying code within the same page, you can omit
actionin your form.Also, put a condition to run PHP once the script has been run.
Hope it helps!
EDIT: I am not sure what is the current filename but to keep it dynamic, I have mentioned
$_SERVER["PHP_SELF"]which is not a recommended usage.However, Try it! 🙂