1

I have created a very simple HTML form, and created a PHP form verbatim from a tutorial, changing only that which I needed to change to match my HTML form. I am getting no error messages, but the form never sends the email. I have posted the two codes below:

HTML

<form action="general.php" method="post" name="genform">
   <label class="contact" for="pronom">First Name:</label>
   <input type="text" name="pronom" autofocus required>
   <label class="contact" for="surname">Last Name:</label>
   <input type="text" name="surname" required><br><br>
   <label class="contact" for="email">Email:</label>
   <input type="email" name="email" required>
   <label class="contact" for="date">Date:</label>
   <input type="date" name="date"><br><br>
   <label class="contact" for="text">Question/Concern:</label>
   <textarea name="text" rows="6" cols="50" required></textarea><br><br>
   <input type="submit" name="send" value="Send Message">
</form>

PHP

<?php
if (isset($_POST['send'])) {
$to = 'me@mymail.org'; //*Changed this, obviously, as well as below
$subject = "New message from $name";
$message = "First Name: " . $_POST['pronom'] . "\r\n\r\n";
$message .= "Last Name: " . $_POST['surname'] . "\r\n\r\n";
$message .= "Email: " . $_POST['email'] . "\r\n\r\n";
$message .= "Date: " . $_POST['date'] . "\r\n\r\n";
$message .= "Message: " . $_POST['text'];
$message = wordwrap($text, 70);
$headers = "From: webmaster@pittcountyaoh.org\r\n";
$headers .= 'Content-Type: text/plain; charset=utf-8';
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
if ($email) {
    $headers .= "\r\nReply-To: $email";
}
$success = mail($to, $subject, $message, $headers, '-fme@mymail.org');
}
?>
<?php if (isset($success) && $success) { ?>
<h1>Thank you!</h1>
<p3>Your message has been sent, and someone will get back to you shortly.</p3>
<?php } else { ?>
<h1>Oops!</h1>
<p3>There was a problem sending your message.</p3>
<?php } ?>

I have tested the mail function with a very simple test php, and it worked. I have checked spam and everything else. Can someone please offer some advice?

Jimmy Wils
  • 19
  • 1

2 Answers2

0

change this line

$headers .= 'Content-Type: text/plain; charset=utf-8';

to,

$headers .= "Content-Type: text/plain; charset=utf-8'";

if still error persist, try this

error_reporting(E_ALL);
ini_set('display_errors', '1');

also try removing from address parameter like this,

$success = mail($to, $subject, $message, $headers);
Ayyanar G
  • 1,545
  • 1
  • 11
  • 24
-1

Mail function Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

parveen
  • 557
  • 3
  • 13