1

I'm having a classic PHP form submission error. I tested the code earlier and it seemed to be working now when testing it again, the email never arrives.

This is the HTML (I changed the site/email address for security reasons of course)

<!-- Contact Form -->
<form method="post" action="http://example.net/assets/mail/mail.php">
  <div class="row 50%">
    <div class="6u 12u(mobile)"><input type="text" name="name" placeholder="Name" />
    </div>
  <div class="6u 12u(mobile)"><input type="email" name="email" placeholder="Email" />
  </div>
</div>
<div class="row 50%">
 <div class="12u"><textarea name="message" placeholder="Message" rows="6"></textarea>
 </div>
</div>
<div class="row">
 <div class="12u">
 <ul class="actions">
 <li>
    <input type="submit" value="Send Message" />
 </li>
 </ul>
   </div>
 </div>
</form>

This is the PHP file:

<?php $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $formcontent="From: $name \n Message: $message";
    $recipient = "es@example.net";
    $subject = "Contact Form";
    $mailheader = "From: $email \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    echo "Thank You!";
?>

The PHP file is located at the same place the HTML links to: http://example.net/assets/mail/mail.php and the email itself is working fine (use it daily). When I test the form out I get the echo/message saying thank you so is definitely finding the PHP file however, I simply don't get anything on my inbox.

Is such a simple code yet I'm really confused and unsure what is going on.

Any help is truly appreciate it.

Kevin Andrid
  • 1,963
  • 1
  • 15
  • 26
StylesTW
  • 11
  • 1

3 Answers3

0

The email could be blocked in the server's mail queue or blocked as spam by the email host. For linux based system, the email is usually logged in the /var/logs directory and there should be an equivalent on windows based servers. From here you should be able to see whether or not the server sends the email out into the world.

Ryan Jenkin
  • 864
  • 8
  • 11
0

The code appears to be correct. The real problem is the use of the mail function of php. If you look at the official documentation, you can see how it is necessary that the parameters passed to the function must meet special requirements. In addition, there are some difference using email() with Windows or Linux.

My advice is to not use direct mail() but a library to send as PHPMailer https://github.com/PHPMailer/PHPMailer

Lipsyor
  • 428
  • 1
  • 7
  • 20
0

Your code is right! It seems like a mail server problem. Try to change the recipient mail address and check if your server is in black list: http://mxtoolbox.com/blacklists.aspx