FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


A simple multiple choice mail form





gidevelop
First of all you will need some minor config's, so create a config.php file like this one

config.php
Code:
<?php
// Date autentificare SMTP
$smtpuser = "smtp username";
$smtppass = "password";

//Subiectul mesajului
$subiect = "Contact" ;

//Dysplayed pages

$formurl = "contact.html" ;
$errorurl = "error.html" ;
$thankyouurl = "thankyou.html" ;
?>


the best smtp server is inmail24.com.

Now we need the processor. The one witch will verify that everything is right. So create now a file called send.php

send php

Code:
<?php
require_once ("/allowrun/smtp.php");
require_once ("config.php");
$nume = $_POST['nume'] ;

//Verifica daca este scris numele
if($nume==""){
exit("Please introduce your name");
}

$email = $_POST['email'] ;
$destinatar = $_POST['destinatar'] ;

//Verifica daca adresa de email este valida
function validate_email($email) {
if (preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i", $email)) {return true;}
else {return false;}
}
if (validate_email($email) == false){exit("Error! Invalid email adress ");}

$mesaj = $_POST['mesaj'] ;

//Verifica daca este scris mesajul
if($mesaj==""){
exit("Please write a message");
}

$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($nume) || empty($email) || empty($mesaj)) {
header( "Location: $errorurl" );
exit ;
}
$nume = strtok( $nume, "\r\n" );
$email = strtok( $email, "\r\n" );
if (get_magic_quotes_gpc()) {
$mesaj = stripslashes( $mesaj );
}

smtpmail("localhost", 25, $smtpuser, $smtppass, $email, $destinatar, $subiect, $mesaj);
header( "Location: $thankyouurl" );
exit ;

?>

This file verify that the mail is written the mail structure and if the name and the message exists. Moving along now. Buld a file named contact.html witch will be your contact form. The code looks like this

contact.html

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Contact</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="send.php" method="post">
  <table width="427" border="0" align="center" cellpadding="8" cellspacing="8" summary="feedback form">
    <tr>
      <td width="92">Name:</td>
      <td width="279"><input name="nume" type="text" id="nume" size="25" /></td>
    </tr>
    <tr>
      <td>Email:</td>
      <td><input type="text" name="email" size="25" /></td>
    </tr>
    <tr>
      <td>To:</td>
      <td><select name="destinatar" id="destinatar">
          <option selected>Selecteaza</option>
        <!----------start modify TO list---------->

          <option value="dan@exemplu.com">Dan</option>
          <option value="mihai@exemplu.com">Mihai</option>

          <!--------end modify TO list-------->
        </select></td>
    </tr>
    <tr>
      <td colspan="2"> <div align="center">Message<br />
          <textarea name="mesaj" cols="55" rows="15" id="mesaj">
</textarea>
        </div></td>
    </tr>
    <tr>
      <td align="center" colspan="2"> <input name="submit" type="submit" value="Send" />
        &nbsp; <input type="submit" name="Submit" value="Erase"> </td>
    </tr>
  </table>
+
</form>
</body>
</html


Now other 2 files are needed the success page and the error page.

thankyou.html

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Success!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<div align="center">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p><font color="#FF0000" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Message sent successfuly!</strong></font></p>
  <p> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">Thank You.</font></p>
</div>
</body>
</html>


error.html

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Error!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<div align="center">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p><font color="#FF0000" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Error sending the message!</strong></font></p>
  <p> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">Unable to send message, please retry.</font></p>
</div>
</body>
</html>


Just another thing for those how want it !!! Free for takeing !!!
roboguyspacedude
Cool. Thank you for posting it thought I don't think I personally can use it. Very Happy
Related topics
PHP: Feedback form issues.. help =P
Simple and Detailed Mail Script
simple php to mysql form doesn't work
The God argument: Is there a God?
PHP Mail Form not sending e-mail to my e-mail
How to build PHP mail form with Spam protection
Prank Excuse Form
Prank Excuse Form
mail form
Multiple Choice Questions
email script question
Help with PHP contact form
Google Sees My mail to form as Spam
Mail Form Suddenly not working..
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.