yangmanrui Posted February 19, 2008 Share Posted February 19, 2008 I have a website where people can learn languages and I would like to add a simple form there. http://www.languagelearninglinks.info/contact.htm Somebody gave me this script, but for some reason it doesn't work. (Could you please someone take a look at it, suggest what I am doing wrong and help me make it work?) thanks manrui <?php if(isset($_POST['email']) && isset($_POST['message'])) { $name = $_POST['name']; $email = $_POST['email']; $msg = $_POST['message']; // You'll want to validate the email and make sure that no one is trying to send this feedback to some one else as well. if(eregi("to:",$email) || eregi("cc:",$email) || eregi('bcc:',$email)) echo'Sorry, we couldn\'t send your message, please try again.'; if(!ereg('^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$', $email)) echo'Sorry, you entered an invalid email address!'; /* * You may also want to run a strip_tags on the message so you don't get radnom html/JS in your emails */ $msg = strip_tags($msg); /* * Please be away that this can still be attacked by spam bots and they may use this to send you junk emails. */ $to = "studentmatters@yahoo.com"; $subject = "Feedback"; $headers = "From: $name <$email>"; mail($to,$subject,$msg,$headers); } ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 Would help if you pointed out what actually doesn't work. Quote Link to comment Share on other sites More sharing options...
yangmanrui Posted February 19, 2008 Author Share Posted February 19, 2008 Well, when I fill the form, and hit send, I never receive any email. manrui Quote Link to comment Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 Check your php.ini file to make sure you have a SMTP server setup Is this a local host or a shared host? Some shared hosts only allow FROM: header to be set to a valid email on your domain. Quote Link to comment Share on other sites More sharing options...
bank Posted February 19, 2008 Share Posted February 19, 2008 Basically, you've tried to use .html as php, take your script and place it in a separate file and name it something like sendmessage.php, then inside your contact.htm file edit this: <form name="form1" method="post" action=""> and change it to this: <form name="form1" method="post" action="sendmessage.php"> You can change sendmessage.php for what ever you decide to call the new file. Also, you should really notify your users that their message has been sent, so swap this /* * Please be away that this can still be attacked by spam bots and they may use this to send you junk emails. */ $to = "studentmatters@yahoo.com"; $subject = "Feedback"; $headers = "From: $name <$email>"; mail($to,$subject,$msg,$headers); } Swap it for: /* * Please be away that this can still be attacked by spam bots and they may use this to send you junk emails. */ $to = "studentmatters@yahoo.com"; $subject = "Feedback"; $headers = "From: $name <$email>"; mail($to,$subject,$msg,$headers); header('location:thanks.html'); } And create a page called thanks.html, it will come up after some one has contacted you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.