TheScriptCenter.com Search:
PHP
PHP Date Script
PHP Get Envelope Variables getenv(var)
PHP Page Counter Script
PHP Autoresponder Mailing Script
PHP Form to Email Script with Anti-Spam features
Jay's PHP Recommend this Site Script
# PHP Form To EMail Script
# Written by Jason Russo #
# http://thescriptcenter.com/
###############################

With this simple, secure form to email php script you can send the contents of any form, and have them emailed to an address of your choosing! I created this script in August of 2005. In July 2008 I dusted it off and re-programmed it basically from scratch. July 24th 2008 released BETA version of this software for download.
Last Updated April 13th, 2009. Currently working on more user friendly version of Ajax form to email for people that wish to use Ajax instead.

PHP 4x users: You wont be able to use SMTP server unless you have PHP 5x but you can still use PHP's mail() process.

Features:
  • Templates that allow you to fully integrate the script into your website.
  • Custom Messages, and Error Codes. You can edit your error codes, and messages so you can personalize every aspect of this script. NO annoying "script written by: " tagged at the end of your messages or embeded into your webpages. Although I do ask for a donation or link back to me! :)
  • Form Examples with plug and play code. I'll include form examples so that you can simply copy/paste the code right into your webpage.
  • Maximum uses per day feature! Help prevent spam and abuse by only allowing x-amount of uses to your website per day.
  • Block Domain Name extentions. Block .ru,.tk, domain or other domain name extentions to help cut down spam or target your geographic location.
  • Help Prevent Spam with optional CAPTCHA function.
  • Send Email via SMTP or standard PHP mail() function.

Requirements:
  • You'll need FTP, or SSH access to the server you plan to run the script from.
  • You'll need a basic understanding of how to upload the files to your server.
  • PHP 4.x or higher. This script hasn't been tested on a windows server and I don't believe it will run on windows at this time.
  • Form *MUST* have a field named email in order for it to function properly. <input type=text name=email>
  • If using CAPTCHA then you'll need to add <img src="includes/captcha.php?.png" alt="CAPTCHA"> <input type="text" name="captchastring" size="30"> to your web form. There is an example on form_example.html
Form Demo
Name:
Email:
Comments:
CAPTCHA
Enter in the Information above. (cAse SeNSItivE!)


Download: formtoemail2.5.zip Number of downloadeds:

Once downloaded, read our Form to Email Documentation.

  • referrers: Separated by commas, this function will prevent spammers from entering an email address from your own domain name.
  • blocked_domains: separated by commas, enter in the domain name extentions you wish to block from using your email script. IE: .ru,.tk will block any email from that domain name extention.
  • ademail: The Email address where the contents of your form will be sent.
  • ccemail: If you wish to CC or send a copy to a specified email.
  • bccemail: Same as above but a "Blind" copy sent.
  • date_format: Shows current date. Uses PHP's date() variables. http://us3.php.net/manual/en/function.date.php;
  • time_format: Same as above;
  • email_to_admin_subject: The subject line of the email where the contents of your form is to be sent;
  • send_auto: Send an autorepsonse message to the person who filled out the form. Uses templates/auto.txt file.
  • email_to_client_subject: The Subject Line of the email if sending an auto response;
  • req_fields: Requires a bit of skill. Separated by commas enter in any required fields on your form. I.E. first_name,address,phone However the field names *MUST* match these names exactely. If first name is a required field then you must have <input type=text name="first_name"> in order for this to function properly.
  • adminpass: The administrative password for form_admin.php
  • max_uses_per_day: How many times a user on your site is allowed to use the script. If they use it more than 1 or 2x, chances are they are just spamming;
  • use_ajax: Advanced users. If you are using Ajax to send the contents of your form set this to 1 See ajax_form_example.html for details;
  • error_invalid_admin_address: Error code shown when your admin address isn't valid. If you set up correctly, then there's no need for this error code.
  • error_email_from_same_domain: Sometimes spammers will attempt to spam your contact forms by entering an email address that is from your own domain. This little checker helps slow spam down so that you only get legitimate requests.
  • error_invalid_domain: Invalid Domain name extention. If the user tries to send an email from one of your blocked domain extentions, this is the message they will see.
  • error_invalid_email_address: Error code shown when the users email address is invalid or blank.
  • error_required_field_empty: Error code shown when a required field was left blank.
  • error_invalid_password: Error Code shown when your administrative password entered doesn't match the password in your config settings.
  • error_session_expired: Error code shown when your cookie has expired in your admin area.
  • usmtp: Use SMTP server or standard php's mail() function.
    • If above is turned on, then change the SMTP settings below.
    • auth: SMTP authentication.
    • helo: yourdomain.com
    • smtpuser: Username of the email address you'll be using
    • smtppass: SMTP password for this account;
    • host: usually your domain.com;
    • port: Standard SMTP port is "25";
  • template_ext: The template extention ".txt" by default. If advanced users wished to use .html extention templates instead you would change this variable.
##########################

10.) Setting up your forms. For now, use the examples in form_example.html and ajax_form_example.html or create your own form.

####################################
## GLOBAL VARIABLES: ##
####################################
<:<HTTP_USER_AGENT>:> - Gives you the web browser type.

<:<date>:> - Shows the date the script was accessed, according to the format you set in the date_format under your admin settings.

<:<time_format>:> - Shows the current time the script was used, according to the format you set in the time_format under your admin settings.

<:<ip>:> - Shows the IP address of the user who accessed the script.






Page Last Updated: 02-08-2010