contact form not emailing specified email address

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

Hi there Roja,

i did the changes you mentioned and im still getting nothing in my inbox.

here is what the code looks like now.

Code: Select all

<?php
$recipient = '***@gmail.com';
$subject = $_POST['contact_name'];
$from = stripslashes($_POST['contact_email']);
$msg = "Message from: $from\n\n".stripslashes($_POST['contact_message']);
mail($recipient, $subject, $msg);
?>
in the mean time while i await your reply i might have a look around for another mailing script ti try.

this is very odd!

also made this if this helps with anything has the <?php phpinfo() ?> in it

http://www.alcoholicclothing.com/test.php
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

Code: Select all

<?php
mail("yourmail@gmail.com","test","hello test","From: mymail@domain.com");
?>
matthijs - i did not recieve a email. nothing happened.
I'm not sure, but my guess is that if this one rule doesn't sent any mail, the problem is not the script but something else (missing or wrong mail configuration etc). But I don't know too much about that, maybe someone else has some ideas?

Here's a simple contact form which works for me:

Code: Select all

<?php
   /**  
  *    Very Basic contact form
  *    14 feb 06
  *
  *----------------------------------- */

// declare an empty error array
$error_message = array();
$return_message = '';

// if form is submitted
if (isset($_POST['submit'])) {

  // is any field empty?
  if(($_POST['name'] == '') || ($_POST['email'] == '') || ($_POST['message'] == '')) 
  {
     $error_message[] = 'Sorry, you seem to have missed out some required fields:';
  }
  // put more input validation here ....! Very important!
  
  // if there are no errors continue
  if(count($error_message) ==0) 
  {
  
     $name = $_POST['name'];
     $email = $_POST['email'];
     $message = $_POST['message'];
     $to = "**********@mail.com";
     if(mail($to,"Contact from your site",$message,"From: $email\n"))
    {
	     $return_message = 'Thanks!';	
     }
     else 
     {
         $return_message = 'Something went wrong mailing!';  

     }
   }
   else
   {
   $return_message = 'Something went wrong!';  
         // normally you would do something with all the error messages from the validation, 
         // but i left that out for simplicity

   }
}		
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>
<body>
<p>
<?php echo (isset($return_message)) ? $return_message : ""; ?>
</p>
<form action="contact2.php" method="post">
Name: <input type="text" name="name" value="<?php echo (isset($_POST['name'])) ? htmlentities($_POST['name']) : ""; ?>"><BR>
Email: <input type="text" name="email" value="<?php echo (isset($_POST['email'])) ? htmlentities($_POST['email']) : ""; ?>"><BR>
Comments:<BR>
<textarea name="message"><?php echo (isset($_POST['message'])) ? htmlentities($_POST['message']) : ""; ?></textarea><BR>
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Roja wrote: The last two are the same.
No they are not, there is a space in front of the second one, while there isn't in the 3rd one.
Roja wrote: Its misleading, and your tone is condescending.
That is a subjective statement. I wasn't intentionally trying to be condescending, nor was it meant to be that way. It's simply a lesson in attention to detail.
Roja wrote: You could have simply stated "The first one has a linefeed before the open php tag".
Yes I could have, but I like to teach by example. And sometimes newbies don't know what line feeds are anyway.
Roja wrote: This is a site for helping and teaching others. Not insulting them.
I enjoy helping others, and I'm pretty sure I didn't insult the original poster. If I insulted you, I am very sorry.
Roja wrote: If you don't understand that, re-read the previous line until you do. ;)
I'm pretty confident that I understand everything you said.
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

Hi Guys,

@matthijs - thanks for your reply. i think you are right that it has something to do with the configeration if all this isnt working.

http://www.alcoholicclothing.com/test.php this link will take you to a page where i have <?php phpinfo() ?> in it does this tell you the configeration?

if someone knows about this can they have a wee look and see if everything is in place or not?

and also matthijs i will try your script out at lunch time and see if that works! itso worth a try i guess.

@agtlewis - thanks for your help before. no need to appoligise to me



i hope to get this working as it is important!

thanks guys
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Maybe sendmail isn't configured properly on that server.

I know that when I write mail scripts on my box at home the mail function never works. I haven't ever bothered to fix it or find out why it doesn't work though. If your paying for hosting and that isn't working you might want to contact them and have them fix it.
Post Reply