<?php

error_reporting(E_ALL ^ E_NOTICE);

/*

Thank you for choosing diyform free version from diyform.me

Version 1.0 June 29th 2025

Copyright diyform 2025

You may not sell this script, but you can use it, copy it or distribute it, providing that you do not delete this copyright notice, and you do not remove any reference or links to diyform or diyform.me

For support, please visit: https://diyform.me/support/

You can get the pro version of this script here: https://diyform.me/
--------------------------------------------------------------------

diyform pro version features:

Set required fields
Attach file uploads
Autoresponder (with optional file attachment)
Auto redirect to "Thank You" page
Google reCAPTCHA support
Block spam words and phrases
Block rude words
Block gibberish (MldMtrPAgZq etc)
Block one-word messages
Block messages with no punctuation
HTML email option
Use email templates
Upload files to the server
Show errors on form page
Show date and time submitted
Create Message ID
CSV output to attachment or file
Show sender's IP address
Block IP addresses
Check for a set cookie
Set character set
Ignore fields
Sort fields
No branding
Free upgrades for life

-----------------------------------------------

DESCRIPTION

diyform is a form processing script written in PHP. It will process any website form and email the contents to you.  Sample form code is provided below for a contact form.  The contents of the form are sent to the email address (or addresses) which you specify below.  The script will not allow a blank form to be sent.

When the form is sent, your visitor will get a confirmation of this on the screen, and will be given a link to continue to your homepage, or other page if you specify it.

This is a PHP script.  In order for it to run, you must have PHP (version 5.3.0 or later) on your webhosting account, and have the PHP mail() function enabled and working.  If you are not sure about this, please ask your webhost about it.

-----------------------------------------------

SETUP INSTRUCTIONS

Step 1: Put the form on your webpage
Step 2: Enter your email address
Step 3: Upload the files to your webspace

Step 1:
-------

Put the form on your webpage.

If using an existing form make sure the form action is "diyform.php", like this example: <form action="diyform.php" method="post">, also make sure that the email input field is named "email" (lower case), like this example: <input type="email" name="email">.  Equally, if you have a name field and you would like the name to show in the email "From:" header, use "name" (lower case), like this example: <input type="text" name="name">.

Sample contact form code.  Copy the code below (between the asterisks) and paste it into your webpage:

***

<form action="diyform.php" method="post" style="box-sizing:border-box; width:500px; max-width:100%; margin:auto; font-family:Arial,sans-serif; background:#000080; color:#ffffff; font-size:120%; padding:20px">	
	Name		
	<p><input type="text" name="name" style="box-sizing:border-box; width:100%; height:40px; font-size:100%"></p>		
	Email		
	<p><input type="email" name="email" style="box-sizing:border-box; width:100%; height:40px; font-size:100%"></p>		
	Message		
	<p><textarea name="message" style="box-sizing:border-box; width:100%; height:200px; font-size:120%"></textarea></p>	
	<p><input type="submit" value="Send" style="font-size:100%; width:100px; height:40px"></p>	
	Powered by <a href="https://diyform.me/" style="color:#ffffff">diyform</a>
</form>

***

Step 2:
-------

Enter your email address.

Enter the email address below to send the contents of the form to, like this example: $my_email = "info@example.com";

Alternatively, you can enter more than one email address, separated by commas, like this example: $my_email = "bob@example.com,sales@example.co.uk,jane@example.com";

*/

$my_email = "";

/*

Optional.  Enter a subject for the email.  The default subject line is shown below.  To change this, enter your own subject between the quotes.

*/

$subject = "Message from contact form";

/*

Optional.  Enter a From: email address.  Only do this if you know you need to.  By default, the email you get from the script will show the visitor's email address as the From: address but a minority of hosts insist that the From: address must be from a domain on the server.  For example, if your website is example.com, then the From: email address must be something@example.com - In such cases, it is not uncommon for the From: ($from_email) address to be the same as the To: ($my_email) address, which on the face of it doesn't look right but won't give you a problem as the visitor's email address goes into a Reply-To: header which means you can hit "reply" to the email and the reply will be sent to the visitor.  You can also use this option if your form does not collect an email address from the visitor, such as a survey, for example, and a From: address is required by your email server.  The default value is: $from_email = "";  Enter the From: email address between the quotes, like this example: $from_email = "contact@example.com";

*/

$from_email = "";

/*

Optional.  Enter the continue link to offer the user after the form is sent.  If you do not change this, your visitor will be given a continue link to your homepage.

If you do change it, remove the "/" symbol below and replace with the name of the page to link to, eg: "mypage.php" or "https://www.elsewhere.com/page.php"

*/

$continue = "/";

/*

Step 3:
-------

Upload the files to your webspace.

Save this file (diyform.php) and upload it to your webspace together with the webpage containing the form.  Put this file in the same directory as the webpage with the form on it.

THAT'S IT, FINISHED!

You do not need to make any changes below this line.

*/

$errors = array();

// Remove $_COOKIE elements from $_REQUEST.

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

// Check email address syntax.

if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{

$_REQUEST['email'] = trim($_REQUEST['email']);

if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ") || stristr($_REQUEST['email'],"\\") || stristr($_REQUEST['email'],":")){$errors[] = "Email address syntax error";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address syntax error";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address syntax error";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address syntax error";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address syntax error"; break;}}}}}}

}

// Check referrer is from same site.

if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}

// Check for a blank form.

function recursive_array_check_blank($element_value)
{

global $set;

if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

}

}

recursive_array_check_blank($_REQUEST);

if(!$set){$errors[] = "You cannot send a blank form";}

unset($set);

if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}

?>
<!DOCTYPE html>

<html>

<head>
<meta name="robots" content="noindex">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>diyform - Website Contact Form PHP Script from diyform.me</title>
<style>
body{
	
font-family:Helvetica,Arial,sans-serif;
text-align:center;
background:#ffffff

}

h1{color:#009900}

.errors{
	
color:#ff0000;
font-weight:bold;
font-size:120%
	
}

a{

text-decoration:underline;
color:#0000ff

}
</style>
</head>

<body>

<?php

// Display any errors.

if(count($errors))
{
	
foreach($errors as $value){print "<p class=\"errors\">" . htmlspecialchars($value) . "</p>" . PHP_EOL;}

}
else
{

// Build message.

function build_message($request_input){if(!isset($message_output)){$message_output = "";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

$message = build_message($_REQUEST);

$message .= PHP_EOL.PHP_EOL . "-- " . PHP_EOL . "Thank you for using diyform from https://diyform.me";

$message = quoted_printable_encode($message);

// utf-8 encode subject.

$subject = "=?utf-8?B?" .  base64_encode($subject) . "?=";

$from_name = "";

if(isset($_REQUEST['name']) && !empty($_REQUEST['name']))
{
	
// utf-8 encode From: name.

$from_name = "=?utf-8?B?" . base64_encode($_REQUEST['name']) . "?=";

}

if(!$from_email){$from_email = $_REQUEST['email'];}

$headers = "From: {$from_name} <{$from_email}>";
$headers .= PHP_EOL;
$headers .= "Reply-To: {$from_name} <{$_REQUEST['email']}>";
$headers .= PHP_EOL;
$headers .= "MIME-Version: 1.0";
$headers .= PHP_EOL;
$headers .= "Content-Type: text/plain; charset=\"utf-8\"";
$headers .= PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable";

mail($my_email,$subject,$message,$headers);

?>
<h1>Message received</h1>
<p><a href="<?php print $continue; ?>">Click here to continue</a></p>
<p>Powered by <a href="https://diyform.me/">diyform</a></p>
<?php

}

?>

</body>
</html>
