I've written a contact form and when I type in 'name, email, and message' I receive the email. However, when I type in the subject it takes me to the 'Thank you' page but I never seem to receive the email.
I've tried changing the different variables in the PHP script but that doesn't work. I can't work out what's stopping the email from being sent. See code below.
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
if(isset($_POST['submit'])){
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$formcontent = "From: $first_name $last_name \n \n Message: $message";
$to = '[email protected]';
$mailheader = "From: $email \r\n";
mail($to, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! Your kind message has been recieved!";
}
?>
<form method="POST" action="mail.php">
<div class="form-inline">
<label for="Firstname">Name</label>
<input type="text" class="form-control"
id="Firstname" name="first_name" placeholder="First Name">
<input type="text" class="form-control"
id="Lastname" name="last_name" placeholder="Last Name">
</div>
<div class="form-group">
<label for="Email">E-mail</label>
<input type="email" class="form-control"
id="Email" name="email" placeholder="Email Address">
</div>
<div class="form-group">
<label for="Subject">Subject</label>
<input type="text" class="form-control"
id="Subject" name="subject" placeholder="Let me know what it's about">
</div>
<div class="form-group">
<label for="Message">Message
</label>
<textarea class="form-control"
id="Message" name="message" rows="6" placeholder="Send me something awesome!"></textarea>
</div>
<button type="submit" name="submit" class="btn btn-default">Submit
</button>
</form>
error_reporting(~1);
what's that tilde doing there? – Funk Forty Niner<input type="text" class="form-control" id="Subject" name="subject" placeholder="Let me know what it's about">
- Try putting it in one line; I've seen that happen before. Same thing for your<textarea>
and email. – Funk Forty Niner