I am a php beginner and I am trying to send form data via email using the php mail() function. For some reason my form is being processed and goes to the thank you page but I am not receiving the emails with the data. I checked my code but can't find what is wrong! can someone please give me a hand? Here is the sample of my code:
<form class="form-wrapper" action="process_form.php" method="post">
<label for="costumer_name">First Name</label><br/>
<input type="text" name="costumer_first_name"/>
<button type="submit">Send</button>
</form>
This is the process_form.php code
<?php
$CustomerFirstName = $_POST['customer_first_name'];
// Build the email
$to = "my@mailinator.com";
$headers = "From: $Email";
$subject = "Red T-shirt Web Order";
$message = "Red T-shirt Order Information:
Customer First Name:".$CustomerFirstName."
";
// Send the mail using PHPs mail() function
mail($to, $subject, $message, $headers);
// Redirect
header("Location: thank_you.php");
?>
Thank you :)
the problem might be on this line:
$headers = "From: $Email";
i dont see $Email
ever instantiated in your code.
Also mail()
works differently for Windows and Linux.
I think you missed specify the SMTP host name
Try just making a static call with:
mail('your@email.com', 'Test Subject', 'Test Message');
If that doesn't work, then it is probably your SMTP server, or lack thereof.
Edit: Also, since $Email is not sent, you're sending a header of 'From: ', which is an invalid header, and will probably cause SMTP to crap out. I know it does on our server, which uses MailEnable, because I've encountered the exact bug before.
$CustomerFirstName = $_POST['customer_first_name'];
<input type="text" name="costumer_first_name"/>
customer_first_name
costumer_first_name
Spot the difference! :-)
Also, $Email
not defined and inside quotes, Would need to be defined and "From: " . $Email;
As Neal mentioned you didn't collect the Email from the form or grab the value for that variable in your PHP code.
Also $CustomerFirstName will not be inserted into your $message with anything because in your PHP code you refer it as
$CustomerFirstName = $_POST['customer_first_name'];
whereas customer is spelled with the letter u but in your HTML you spelled it with a letter o.