Jump to content

Email contact form


Sigmahokies

Recommended Posts

Hi everyone,

 

I'm not sure if it is right code to send email from email form in HTML and PHP. I tested it to send to my email, it is not work...can you help me? Also, I'm not sure I understand what is difference between $_POST and $_REQUEST, I know $_REQUEST is good for email, but few tutorial about email contact using $_POST and $_GET. How $_REQUEST works? I checked php.net, seem it is not explain very clear...even i went to W3school.com to learn about $_REQUEST, still not clear about it.

 

Also, I wonder...will "Webmail" such as gmail.com, yahoo.com, etc...work with any server with PHP?

 

However, Here my code that I wrote:

 

<?php $action=$_REQUEST['action']; if ($action=="")    /* display the contact form */     {     ?>     <!doctype html>    <html>    <head>    <title>Contact Form</title>    <link href="contact.css" rel="stylesheet" type="css/text">    </head>    <body>    <form  action="" method="POST" enctype="multipart/form-data">     <input type="hidden" name="action" value="submit">     Your name:<br>     <input name="name" type="text" value="" size="30"/><br>     Your email:<br>     <input name="email" type="text" value="" size="30"/><br>     Your message:<br>     <textarea name="message" rows="7" cols="30"></textarea><br>     <input type="submit" value="Send email"/>     </form>    </body>    </html>    <?php     }  else                /* send the submitted data */     {     $name=$_REQUEST['name'];     $email=$_REQUEST['email'];     $message=$_REQUEST['message'];     if (($name=="")||($email=="")||($message==""))         {         echo "All fields are required, please fill <a href=\"\">the form</a> again.";         }     else{                 $from="From: $name<$email>\r\nReturn-path: $email";         $subject="Message sent using your contact form";         mail("XXXXXXXX@gmail.com", $subject, $message, $from);         echo "Email sent!";         }     }   ?> 
Anyone who can help, thank you so much!
Link to comment
Share on other sites

This is what the manual says about $_REQUEST:

 

An associative array that by default contains the contents of $_GET, $_POST and $_COOKIE.

That's what it is, it has everything in $_GET, $_POST, and $_COOKIE combined into one place. Most code will specifically use one of those, like $_POST, if the code is supposed to handle a form that was submitted via post.

 

For your code, the first thing you should do is add this to the top:

 

ini_set('display_errors', 1);
error_reporting(E_ALL);
Link to comment
Share on other sites

  • 2 weeks later...

Question, where exactly are you running this code from? From localhost server? Then its probably not setup to send mail using mail(), also mail sent this way can be temperamental at times and take time to be processed, placed in spam folder or rejected completely.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...