|
|
|
|
Like this code?
Show the author your appreciation.
|
|
| |
Name=Easy Form Mailer
Version=1.5
Date= November 14, 2006
Developer=Md. Zakir Hossain (Raju)
Email=rajuru(at)gmail(dot)com
URL=http://www.rajuru.xenexbd.com
License: LGPL
I appreciate the email's last credit line but not mandatory.
A thank is highly deserved
Overview:
Using this script anyone can easily get form result to his/her mailbox.
You can use this script for any form 2 mail purpose.
You can define mandatory fields without a single line of code.
Just put __ (double underscore) before field name.
You can show custom message on success or failure of submission.
How to Use:
1. Create a new page and design form.
2. You can use as many fields as you wish
3. put __ (double underscore) before the name of any compolsory
fields. suppose username field is mandatory. so its name
should be __username
4. Create at least three hidden fields as below
Name Value
----- ----------------------------------------------
Email_Recipient your email address where you wish to receive email
Email_Sender your mail subject
Email_Subject send address, you can use an email box for visitors
to give his email address
5. Optionally you can create 3 more hidden fields
Name Value
------ ----------------------------------------------
Email_Success Message after mail sending success
Email_Failure Message if mail sending fails
Return_Url The address where user should be back after
successful submission
Note: These 6 fields are case-sensitive
mailer.php
| <?php
/*
Name=Easy Form Mailer
Version=1.5
Date= November 14, 2006
Developer=Md. Zakir Hossain (Raju)
Email=rajuru(at)gmail(dot)com
URL=http://www.rajuru.xenexbd.com
License: LGPL
I appreciate the email's last credit line but not mandatory. A thank is highly deserved
*/
print_r($_POST);
//check for 3 required fields, these fields are made with Case-sensitivity
if(empty($_POST['Email_Recipient'])) die("No Email Recipient");
if(empty($_POST['Email_Sender'])) die("No Email Sender");
if(empty($_POST['Email_Subject'])) die("No Email Subject");
$to=$_POST['Email_Recipient'];
$from=$_POST['Email_Sender'];
$subject=$_POST['Email_Subject'];
unset($_POST['Email_Recipient']);
unset($_POST['Email_Sender']);
unset($_POST['Email_Subject']);
//success message, you can define one with hidden field. hidden field name must be "Email_Success"
if(!empty($_POST['Email_Success'])) {
$success=$_POST['Email_Success'];
} else {
$success= "Form submitted Successfully";
}
unset($_POST['Email_Success']); //unset this variable
//Failure message, you can define one with hidden field. hidden field name must be "Email_Failure"
if(!empty($_POST['Email_Failure'])){
$failure=$_POST['Email_Failure'];
} else {
$failure="Form submission failed. Sorry for this inconvenience";
}
unset($_POST['Email_Failure']); //unset this variable
//set return url after successfully completing submission
if(!empty($_POST['Return_Url'])){
$returnurl=$_POST['Return_Url'];
} else {
$returnurl=$_SERVER['HTTP_REFERER'];
}
unset($_POST['Return_Url']); //unset return url
$msg="";
foreach ($_POST as $Field=>$Value){
if(substr($Field,0,2)=="__"){ //field started with double underscore which means they are required fields
if(empty($Value)){
die("You must enter ".substr($Field,2)."<br/><a href=\"javascript:history.go(-1)\">Go Back</a>"); //cancel script
} else {
$msg .= substr($Field,2) .": <b>". $Value."</b>"; //strip first two character as they are double underscore
$msg .="<br>";
}
} else {
$msg .= $Field .": <b>". $Value."</b>";
$msg .="<br>";
}
}
$msg.= "<br/><br/>Script by <a href=\"http://www.rajuru.xenexbd.com\">Md. Zakir Hossain (Raju)</a>";
/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
/* additional headers */
$headers .= "To: $to \r\n";
$headers .= "From: $from \r\n";
$headers .= "Subject: $subject \r\n";
/* and now mail it */
if (@mail($to,$subject, $msg, $headers)) {
echo "<b>$success</b><br/><a href=\"$returnurl\">Go Back</a>";
} else {
echo "$failure <br/><a href=\"javascript:history.go(-1)\">Go Back</a>";
}
?> | |
Usage Example
| <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-us">
<title>Form Submission</title>
</head>
<body>
<hr>
<form action="mailer.php" method="POST" enctype="multipart/form-data">
<h2>Form Submission Sample</h2>
<p>Make up a username:<br>
<input type="text" size="25" maxlength="256" name="__Username"> -- <em>you
can use mixed case</em><br>
Make up a password:<br>
<input type="password" size="25" maxlength="256" name="__Password"> -- <em>
help keep this private!</em><br>
Enter password again:<strong><br>
</strong>
<input type="password" size="25" maxlength="256" name="__PasswordVerify"> --
<em>for verification</em><br>
Enter e-mail address:<strong><br>
</strong><input type="text" size="25" maxlength="256" name="__EmailAddress">
-- <em>if you have one</em></p>
<p><input type="text" size="25" maxlength="256" name="Firstname"> - First
Name</p>
<p><input type="text" size="25" maxlength="256" name="Lastname"> - Last Name</p>
<h2><input type="submit" value="Register Me">
<input type="reset" value="Clear Form"></h2>
<input type="hidden" name="Email_Recipient" value="rajuru@gmail.com">
<input type="hidden" name="Email_Sender" value="test@gmail.com">
<input type="hidden" name="Email_Subject" value="Membership Request">
<input type="hidden" name="Email_Success" value="Request Submitted, thanks for your time">
<input type="hidden" name="Email_Failure" value="An unknown error occured while submitting your form.">
<input type="hidden" name="Return_Url" value="<?php echo $_SERVER['HTTP_REFERER'];?>">
</form>
<hr>
</body>
</html> | |
|
|
| send php mail with form data and attachment. Categories : PHP, Email, Mail, Form Processing | | | Db_lib - practical example usage of database abstraction and form validation.
Categories : PHP, Form Processing, PHP Classes, Data Validation, Beginner Guides | | | Simple PHP Form Field Generator Categories : PHP, Beginner Guides, Form Processing, HTML and PHP | | | Form Validation Using PHP to highlight non valid fields Categories : PHP, Form Processing, Data Validation, Beginner Guides | | | Sql Builder Categories : PHP, HTML and PHP, Databases, General SQL, Form Processing | | | Upload any fixed type of files, control file type through javascript and encrypt filename using php so file not get overwrite Categories : PHP, Java Script, Functions, PHP References, Form Processing | | | Email Class Categories : PHP, Mail, PHP Classes | | | Protect your email links from being spidered by spam email robots! Categories : PHP, Security, Mail, Email | | | Data Retrieve from mailbox and generate the SQL Syntax Categories : PHP, IMAP, Mail | | | XPertMailer - Sends TRUE Mails Categories : PHP, Mail, SMTP, PHP Classes | | | Tell a friend script :) Categories : PHP, Mail | | | addslashes automatically to $_POST variables Categories : PHP, Form Processing, Security | | | Form Elements Class Categories : PHP, PHP Classes, Form Processing | | | Dynamic form field Categories : PHP, HTML and PHP, Form Processing | | | Creates a CAPTCHA image in PHP, which displays 5 numbers stored in a session. Categories : PHP, GD image library, Form Processing, Security | |
| | | | Ruth Nisenbaum wrote :1666
This script is very dangerous because spammers can use this unprotected code in your site to send thousands of emails as spam.
What spammers usually do is write a form that connects to your server side. The server side does not check the data input since it assumes that the data comes from its own form.
| |
|
|
|