Jump to content


Photo

Not Receiving Email


  • Please log in to reply
7 replies to this topic

#1 Mig

Mig
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 September 2006 - 03:13 PM

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:

<?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
}
?>
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.

#2 stef686

stef686
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 September 2006 - 03:19 PM

mail($to, $subject, £message)


"£" instead of "$"

That might be something to do with it but I can't check it myself right now I'm afraid

#3 gerkintrigg

gerkintrigg
  • Members
  • PipPipPip
  • Magician
  • 828 posts
  • LocationBristol, UK
  • Age:37

Posted 14 September 2006 - 05:45 PM

and maybe change example@site.com to your address?
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books

#4 karthikeyan_coder

karthikeyan_coder
  • Members
  • PipPipPip
  • Advanced Member
  • 201 posts

Posted 14 September 2006 - 07:42 PM

find:
mail($to, $subject, £message)

Replace with:
mail($to, $subject, $message);

www.karthi.us

#5 Mig

Mig
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 15 September 2006 - 10:10 AM

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.

#6 Mig

Mig
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 15 September 2006 - 10:21 AM

Ok, I have simplified the code even more and still no emails. Surely there is nothing wrong with this 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
}
?>


#7 stef686

stef686
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 15 September 2006 - 10:56 AM

<form id="contactform" name="contactForm" method="post">

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:

<form id="contactform" name="contactForm" action="contact.php" method="post">

For example, if the file is called contact.php

#8 Mig

Mig
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 15 September 2006 - 02:03 PM

But this code is from contact.php. It's not going anywhere..?

Anyway I tried that but still no emails.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users