This demonstrates gathering information to use on your website.
With the exception of SMTP examples, PHPMailer Pro will automatically detect the MTA (Mail Transfer Agent). There is no requirement to add properties for IsQmail, IsSendmail, or IsMail. The properties are deprecated and removed.
<?php
/**
* This is a sample appointment form to demonstrate how
* Form2Mail works.
* The default mail transport is sendmail ( not PHP mail() )
* Also supported, in order, are PHPMailerLite.php or PHPMailer Pro.php
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$show_form = true;
$reload_form = true;
if (count($_POST) > 0) {
/**
* Check if the hidden honeypot fields are filled out. If not, send a mail.
* there are two honeypot fields, both are initially set with an empty value
* if any are filled in, a bot or hacker is at work, reject
*/
$hacker = false;
/* alternate */
/*
$hpot_arr = array('hpot_url','hpot_okurl');
foreach ($hpot_arr as $test_hack) {
if (isset($_POST[$test_hack]) && !empty($_POST[$test_hack])) { $hacker=true;unset($_POST[$test_hack]);}
}
/* */
if ( isset($_POST['hpot_url']) && !empty($_POST['hpot_url'])) { $hacker=true;unset($_POST['hpot_url']); }
if ( isset($_POST['hpot_okurl']) && !empty($_POST['hpot_okurl'])) { $hacker=true;unset($_POST['hpot_okurl']); }
if ( $hacker === true ) { exit('Unable to process<br>'); }
$hacker = null;unset($hacker);
/* END honeypot bot/hacker check */
/* VALIDATION */
require('assets/mailer/FormValidator.php');
$validator = new codeworxtech\FormValidator('en');
$validator->addValidation("Name","required","Full name is required.");
$validator->addValidation("Name","nourl","No URL allowed.");
$validator->addValidation("Email","required","Email address is required.");
$validator->addValidation("Email","email","Provide a valid email address.");
$validator->addValidation("Testimonial","required","Testimonial is required.");
$validator->addValidation("Testimonial","nourl","No URL allowed.");
if($validator->ValidateForm()) {
$required = 'Name,Email,Testimonial';
$reserved_keys = 'hpot_url,hpot_okurl';
$setSender = ['noreply@' . $_SERVER['HTTP_HOST']=>'No Reply (unmonitored)'];
$setRecipient = ['yourname@yourdomain.com'=>'Your Name'];
$subject = 'Contact Us Form from: ' . $_SERVER['HTTP_HOST'];
$useEnvRpt = false;
$refreshWaitMinutes = 0;
$redirect = "sample_thankyou.php?t=testimonial";
// $SMTP_Host = 'smtp.yourhost.com';
// $SMTP_Account = [ 'youraccount@yourhost.com' => 'yourpassword' ];
require 'assets/mailer/Form2Mail.php';
exit();
} else {
$error_hash = $validator->GetErrors();
$error_dump = '';
foreach($error_hash as $inpname => $inp_err) {
$errorVar = $inpname . '_error';
$$errorVar = '<br><span id="' . $errorVar . '" class="s_error">▲ ' . $inp_err . '</span>';
}
foreach ($_POST as $key => $val) {
$$key = $val;
}
}
}
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Form2Mail Sample Contact Us form</title>
<link href="https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@400;500;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha512-SfTiTlX6kk+qitfevl/7LibUOeJWlt9rbyDn92a1DqWOw9vWG2MFoays0sgObmWazO5BQPiFucnnEAjpAB+/Sw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.2/css/bulma.min.css" />
<style>
.required {
font-size:0.8rem;
color:red;
}
</style>
</head>
<body>
<section class="container">
<div class="columns is-multiline">
<div class="column is-10 is-offset-1">
<div class="columns">
<div class="column left">
<h1 class="title is-1">Form2Mail<br>Sample Form:<br>Testimonial</h1>
<h2 class="subtitle colored is-4">To fully test this sample form:</h2>
<p>
To fully test, add your email address to $setRecipient
in the php code at the top of this form ... then go ahead and submit a test.
</p>
</div>
<div class="column right has-text-left">
<form method="POST" enctype="multipart/form-data">
<div class="field">
<label class="label" for="Name">Name <span class="required">✱</span></label>
<div class="control">
<input class="input is-medium" type="text" name="Name" value="<?php echo (isset($Name)) ? $Name : ''; ?>" required autofocus />
<?php echo isset($Name_error) ? $Name_error : ''; ?>
</div>
</div>
<div class="field">
<label class="label" for="Email">Email <span class="required">✱</span></label>
<div class="control">
<input class="input is-medium" type="text" name="Email" value="<?php echo (isset($Email)) ? $Email : ''; ?>" required />
<?php echo isset($Email_error) ? $Email_error : ''; ?>
</div>
</div>
<div class="field">
<div class="one-third">
<label class="label" for="Rating">Rating </label>
</div>
<div class="two-thirds">
<div class="select is-fullwidth">
<select name="Rating" id="Rating">
<?php $checked = ''; if (isset($Rating) && $Rating == '10') { $checked = ' checked="checked"'; } ?>
<option value="10"<?php echo $checked; ?>>10</option>
<?php $checked = ''; if (isset($Rating) && $Rating == '9') { $checked = ' checked="checked"'; } ?>
<option value="9"<?php echo $checked; ?>>9</option>
<?php $checked = ''; if (isset($Rating) && $Rating == '8') { $checked = ' checked="checked"'; } ?>
<option value="8"<?php echo $checked; ?>>8</option>
<?php $checked = ''; if (isset($Rating) && $Rating == '7') { $checked = ' checked="checked"'; } ?>
<option value="7"<?php echo $checked; ?>>7</option>
<?php $checked = ''; if (isset($Rating) && $Rating == '6') { $checked = ' checked="checked"'; } ?>
<option value="6"<?php echo $checked; ?>>6</option>
<?php $checked = ''; if (isset($Rating) && $Rating == '5') { $checked = ' checked="checked"'; } ?>
<option value="5"<?php echo $checked; ?>>5</option>
<?php $checked = ''; if (isset($Rating) && $Rating == '4') { $checked = ' checked="checked"'; } ?>
<option value="4"<?php echo $checked; ?>>4</option>
<?php $checked = ''; if (isset($Rating) && $Rating == '3') { $checked = ' checked="checked"'; } ?>
<option value="3"<?php echo $checked; ?>>3</option>
<?php $checked = ''; if (isset($Rating) && $Rating == '2') { $checked = ' checked="checked"'; } ?>
<option value="2"<?php echo $checked; ?>>2</option>
<?php $checked = ''; if (isset($Rating) && $Rating == '1') { $checked = ' checked="checked"'; } ?>
<option value="1"<?php echo $checked; ?>>1</option>
</select>
</div>
</div>
<div class="clear-fix" style="margin-bottom:0;"></div>
</div><!-- END field -->
<div class="field">
<label class="label" for="Testimonial">Testimonial <span class="required">✱</span></label>
<div class="control">
<textarea class="textarea is-medium" name="Testimonial" required><?php echo (isset($Testimonial)) ? $Testimonial : ''; ?></textarea>
<?php echo isset($Testimonial_error) ? $Testimonial_error : ''; ?>
</div>
</div>
<div class="field is-viz">
<label class="label" for="hpot_url">Leave blank and submit</label>
<div class="control">
<input class="input is-medium" type="text" id="hpot_url" name="hpot_url" value="" placeholder="Your website url, include http or https" autocomplete="off" />
</div>
</div>
<div class="field is-viz">
<label class="label" for="hpot_okurl">Leave unchecked to submit</label>
<div class="control">
<input type="checkbox" id="hpot_okurl" name="hpot_okurl" value="" />
</div>
</div>
<div class="control">
<input class="button is-link is-fullwidth has-text-weight-medium is-medium" type="submit" value="Send Message" name="Submit">
</div>
</form>
<span class="required">✱</span> = required<br>
</div>
</div>
</div>
<div class="column is-8 is-offset-2">
<br>
<nav class="level">
<div class="level-left">
<div class="level-item">
<span class="icon">
<a href="https://twitter.com/PHPMailer_2" target="_blank">
<i class="fa fa-twitter fa-lg" title="Follow on Twitter"></i>
</a>
</span>
<span class="icon">
<a href="https://www.facebook.com/groups/phpmailer2" target="_blank">
<i class="fa fa-facebook fa-lg" title="Follow on Facebook"></i>
</a>
</span>
<span class="icon">
<i class="fa fa-github fa-lg" title="Follow on Github"></i>
</span>
<span class="icon">
<a href="mailto:andy@codeworxtech.com?subject=Contact%20Us%20form%20enquiry&body=I%20am%20interested%20%0D%0A%0D%0A" rel="nofollow"
<i class="fa fa-envelope fa-lg" title="Send an Email"></i>
</a>
</span>
</div>
</div>
<div class="level-right">
<small class="level-item" style="color: var(--textLight)">
© Your Copyright Message Here. All Rights Reserved.
</small>
</div>
</nav>
</div>
</div>
</section>
</body>
<style>
:root {
--brandColor: hsl(166, 67%, 51%);
--background: rgb(247, 247, 247);
--textDark: hsla(0, 0%, 0%, 0.66);
--textLight: hsla(0, 0%, 0%, 0.33);
}
body {
background: var(--background);
height: 100vh;
color: var(--textDark);
}
.field:not(:last-child) {
margin-bottom: 1rem;
}
.register {
margin-top: 10rem;
background: white;
border-radius: 10px;
}
.left,
.right {
padding: 2.5rem;
}
.left {
border-right: 5px solid var(--background);
}
.left .title {
font-weight: 800;
letter-spacing: -2px;
}
.left .colored {
color: var(--brandColor);
font-weight: 500;
margin-top: 1rem !important;
letter-spacing: -1px;
}
.left p {
color: var(--textLight);
font-size: 1.15rem;
}
.right .title {
font-weight: 800;
letter-spacing: -1px;
}
.right .description {
margin-top: 1rem;
margin-bottom: 1rem !important;
color: var(--textLight);
font-size: 1.15rem;
}
.right small {
color: var(--textLight);
}
input {
font-size: 1rem;
}
input:focus {
border-color: var(--brandColor) !important;
box-shadow: 0 0 0 1px var(--brandColor) !important;
}
.fa {
color: var(--textLight);
margin-right: 1rem;
}
.is-viz {
display:none;
}
.textarea:not([rows]) {
max-height: 40em;
min-height: 5em;
}
</style>
</html>
Download