PHP Email Form v1 PHP Script

PHP Email Form v1 PHP Script

Introduction:
This tutorial will cover creating an email form with PHP/HTMl.

Pre-creation:
Before you do this, please note that some errors may be caused by your php.ini file located on your server (online or local) during the actual mail sending process (if they do not arrive, for example).

Steps of Creation:
Step 1:
First we are going to create our HTML form for the user to interact with. We will take three fields; Name, Their email, Message.

 
 

<html>
      <head></head>
      <body>
            <form action='mail.php' method='POST'>
                  <input type='text' name='nam' />
                  <input type='text' name='email' />
                  <input type='text' name='message' />
                  <input type='submit' value='Send' name='sub' />
            </form>
      </body>
</html>

 

 

Please note; the action is mail.php because that is what the file containing my email form is called (this avoids having to create multiple, un-needed files).

Step 2:
Next let's go to PHP and check if the form has been submitted (if the submit button is set).

 
 

<?php
      if (isSet($_POST['sub'])) {

      }
?>

 

Step 3:
Now we will set our local variables of the form values. Then we will check if all of the values are set; if they're not we'll echo an error.

 
 

$name = $_POST['nam'];
$email = $_POST['email'];
$message = $_POST['message'];
if ($name == '' || $email == '' || $message == '') {
      echo 'Not all the values have been set. Please try again.';
}else{

}

 

Step 4:
Finally, we will use the mail function to submit the email with the given form values.

 
 

$msg = 'NAME: '.$name.', EMAIL: '.$email.', MESSAGE: '.$message;
$m = mail('<a href="mailto:youremail@domain.ext" rel="nofollow">youremail@domain.ext</a>', 'New Email Contribution!', $msg);
if ($m){
      echo 'Mail sent!';
}else{
      echo 'Mail error!';
}

 

 

 

Comments

Popular posts from this blog

Motos Android Mame Game Download

StatusNet Micro Blog PHP Script Free Download

1941 Counter Attack (Japan) Windows Game Download