Jump to content

Not Receiving Email


Mig

Recommended Posts

Ok, I am sure contact form questions get asked here like 1000 times a day, but this really has me stumped.

I just don't receive any emails. I tested the mail() function and it returns true so I don't know why I don't receive an email. Here is my code:

[code]<?php
$errmsg = "";
$name = "";
$email = "";
$subject = "";
$message = "";
if(isset($_POST["send"])) {
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$subject = trim($_POST["subject"]);
$message = trim($_POST["message"]);
if ($name == "") {
$errmsg = "Please enter your name";
} else if (!preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $email)) {
$errmsg = "Invalid email address";
} else if ($message == "") {
$errmsg = "Please enter a message";
}
if ($errmsg == "") {
$to = "example@site.com";
mail($to, $subject, $message)
?>
      <div style="margin-top:60px; text-align:center; height:160px">
        <h1>Thank you for your message.</h1>
        <p><a href='#'>Return to Home page</a></p>
      </div>
<?php
}
}
if (!isset($_POST["send"]) || $errmsg != "") {
?>
      <div id="error" class="contactFormError"><?=$errmsg;?></div>
      <table width="100%" style="margin-top:20px;">
        <form id="contactform" name="contactForm" method="post">
          <tr height="25px">
            <td width="70px" align="right" ><h2 class="contactTitle">Name:&nbsp;&nbsp;</h2></td>
            <td><input type="text" id="name" name="name" size="40" class="contactField" value="<?=$name;?>"></td>
          </tr>
          <tr height="25px">
            <td align="right"><h2 class="contactTitle">Email:&nbsp;&nbsp;</h2></td>
            <td><input type="text" id="email" name="email" size="40" class="contactField" value="<?=$email;?>"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr height="35px">
            <td align="right"><h2 class="contactTitle">Subject:&nbsp;&nbsp;</h2></td>
            <td><input type="text" id="subject" name="subject" size="40" class="contactField" value="<?=$subject;?>"></td>
          </tr>
          <tr>
            <td valign="top" align="right"><h2 class="contactTitle">Message:&nbsp;&nbsp;</h2></td>
            <td><textarea rows="10" id="message" name="message" cols="60" class="contactField"><?=$message;?></textarea></td>
          </tr>
          <tr height="35px">
            <td>&nbsp;</td>
            <td><input type="submit" id="send" name="send" value="Send Message"></td>
          </tr>
        </form>
      </table>
      <?php
}
?>[/code]
I've edited out all the unnecessary stuff from the HTML here and also simplified the php so that it's not getting anything wrong with validation or something. Still, I get no emails. I've tried different email addresses too. It's not in Junk either.
Link to comment
Share on other sites

No, sorry that was just a typo when I posted the code here. I changed it to be more simple so that I could make sure there were absolutely no errors with validation or concatenation or something. I've change the £ to a $ now.

The email address I just changed just as an example. I have tried it with 3 real addresses, none of which receive email.
Link to comment
Share on other sites

Ok, I have simplified the code even more and still no emails. Surely there is nothing wrong with this code:

[code]<?php
$errmsg = "";
$name = "";
$email = "";
$subject = "";
$message = "";
if(isset($_POST["send"])) {
$name = $_POST["name"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$to = "example@site.com";
mail($to, $subject, $message);
} else {
?>
      <table width="100%" style="margin-top:20px;">
        <form id="contactform" name="contactForm" method="post">
          <tr height="25px">
            <td width="70px" align="right" ><h2 class="contactTitle">Name:&nbsp;&nbsp;</h2></td>
            <td><input type="text" id="name" name="name" size="40" class="contactField" value="<?=$name;?>"></td>
          </tr>
          <tr height="25px">
            <td align="right"><h2 class="contactTitle">Email:&nbsp;&nbsp;</h2></td>
            <td><input type="text" id="email" name="email" size="40" class="contactField" value="<?=$email;?>"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr height="35px">
            <td align="right"><h2 class="contactTitle">Subject:&nbsp;&nbsp;</h2></td>
            <td><input type="text" id="subject" name="subject" size="40" class="contactField" value="<?=$subject;?>"></td>
          </tr>
          <tr>
            <td valign="top" align="right"><h2 class="contactTitle">Message:&nbsp;&nbsp;</h2></td>
            <td><textarea rows="10" id="message" name="message" cols="60" class="contactField"><?=$message;?></textarea></td>
          </tr>
          <tr height="35px">
            <td>&nbsp;</td>
            <td><input type="submit" id="send" name="send" value="Send Message"></td>
          </tr>
        </form>
      </table>
      <?php
}
?> [/code]
Link to comment
Share on other sites

[code]<form id="contactform" name="contactForm" method="post"> [/code]

There is no "action" parameter telling the form to go anywhere when submitted to be processed. Simply put in the name of the file that you've shown us into the action parameter:

[code]<form id="contactform" name="contactForm" action="contact.php" method="post"> [/code]

For example, if the file is called contact.php
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.