My PHP form is sending me blank emails.
I'm not sure where the issue is and wondered if anyone would be kind enough to help out.
Here's the HTML
<div class="form">
<form method="post" action="send_contact.php">
<div class="form_row">
<label>Your Name:</label>
<input type="text" name="name" class="main_input" />
</div>
<div class="form_row">
<label>Your Email:</label>
<input type="text" name="email" class="main_input" />
</div>
<div class="form_row">
<label>Type of Inquiry:</label>
<input type="text" name="inquiry" class="main_input" />
</div>
<div class="form_row">
<label>Your Message:</label>
<textarea name="message" class="main_textarea"></textarea>
</div>
<div class="form_row">
<input type="submit" class="submit" value="Submit" >
</div>
</div>
</form>
</div>
Here's the PHP
<?php
$subject = "$inquiry";
$message = "$message";
$mail_from = "$email";
$header = "from: $name <$mail_from>";
// Enter your email address
$to ='inquiries@openrhythmnetwork.com';
$send_contact = mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>
Literally, all I'm receiving is a blank email with no subject heading...
The following has been tested and working on my server. PHP Version 5.4
PHP (send_contact.php)
<?php
$name = $_POST['name'];
$subject = $_POST['inquiry'];
$message = $_POST['message'];
$mail_from = $_POST['email'];
$header = "From: $name <$mail_from>";
// Enter your email address
$to ='email@example.com'; // change to your Email address
$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";
}
?>
HTML form:
<div class="form">
<form method="post" action="send_contact.php">
<div class="form_row">
<label>Your Name:</label>
<input type="text" name="name" class="main_input" />
</div>
<div class="form_row">
<label>Your Email:</label>
<input type="text" name="email" class="main_input" />
</div>
<div class="form_row">
<label>Type of Inquiry:</label>
<input type="text" name="inquiry" class="main_input" />
</div>
<div class="form_row">
<label>Your Message:</label>
<textarea name="message" class="main_textarea"></textarea>
</div>
<div class="form_row">
<input type="submit" class="submit" value="Submit" >
</div>
</div>
</form>
</div>
You should be using variables like $_POST['inquiry']
to access the post data.
Incidentally, using raw user data in an email is a good way to have your script turned into a spam system. http://en.wikipedia.org/wiki/Email_injection
You need to assign variable from $_POST
array
$subject = htmlentities($_POST['inquiry']);
// and so on
You need to use $_POST array variables to access the POSTed info from a form, like this:
$subject = $_POST['inquiry'];
$message = $_POST['message'];
$mail_from = $_POST['email'];
It would also be wise to read this now legendary post about how to prevent SQL injection in PHP.