-1

I have an HTML form that posts to a PHP mail function. For some reason it does not send the content anymore. The emails display "This email has no content." Am I missing something?

//HTML - Post method form. 

<form class="form" id="form" action="submitform.php" method="post">
<h2 style="padding-top: 10px;">Contact Us</h2>
<input class="input" type="text" placeholder="Name" name="name"><br>
<input class="input" type="text" placeholder="E-Mail Address" name="email"><br>
<input class="input" type="text" placeholder="Phone #" name="phone"><br>
<textarea class="input" placeholder="Questions, Specifications, etc." 
name="message</textarea>
<input class="inputButton" type="submit">
</form> 

//PHP - Gets posted HTML input data and sends it to the email, formatted with \n 

<?php 
$to = 'example@example.com' ;
$subject = 'Inquiry' ; 
$name = $_POST['name'] ; 
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$message = $_POST['message'] ;

$message = "From: $name  \nEmail: $email \nPhone: $phone \nMessage: $message \n";

$sent = mail ($to, $subject, $message) ; 
if($sent == true) {
echo "<h3>Thank you for your inquiry.</h3>"; 
}else{
echo "<h3>Sorry, your message wasn't sent.</h3>; 
}
?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
badja
  • 1

1 Answers1

1

I've found defining headers, even if I just want default values, helps me get my mail delivered. I can't say this is what you need to do because your code looks like it should run successfully as is.

An example of setting the headers to (I believe) default values:

    $to = $to_email;
    $subject = $your_subject;
    $message = $your_message;
    $headers = "From: S.O.<no-reply@dontusethis.email>\r\n" . 
               "Reply-To: [can be nice, not needed of course]\r\n" .
               "X-Mailer: PHP/" . phpversion();
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";        
    mail($to,$subject,$message,$headers);
TCooper
  • 1,545
  • 1
  • 11
  • 19