DISCLAIMER These examples are provided for informational purposes only and are not recommendations. The code examples are open source and available online. Please note that everything you do with these provided code examples is at your own risk.
In Nicepage, you can create simple HTML forms using the Contact Form Element. The Contact Form Element is set by default to send data to the account email if you have an active Nicepage license. As an alternative to the built-in Email Submission, you can create a working HTML Contact Form using a third-party script. Generally, you can use any script.
NOTE: Each script requires specific form classes, such as names and IDs, and sometimes, you have to follow a particular form structure. Nicepage uses the predefined Field Names for the Contact Form Element. You must not change the Name Attributes.
Using WordPress or Joomla, you can use the popular methods to submit forms. You can learn about other Contact Form Submit options.
Add Contact Form
Please follow the steps below to add the Contact Form Element and assign it to a script that sends emails to your email address.
- Add the Contact Form Element from the Add Panel.
- Edit the Contact Form Fields.
- Specify the path to the Script file in the Contact Form Submit URL field.
- Export your website in HTML. Upload your website to a server.
NOTE: The path to the PHP script can be absolute or relative. The script URL usually contains the Path and File Name. In this example, we will use contact.php in the website's root folder.
IMPORTANT: Please verify that your server is set to send emails.

Add PHP Script
After adding the Contact Form, you should create a PHP file to send emails. Create the contact.php file in the root of your server folder and paste one of the following code examples.
Sample 1
The simplest Email Action uses the Name, Email, and Message fields. Replace placeholders like *YOUR_EMAIL*with the email address. You need the proper server setup to send emails to and from any domain.
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
//Specify the message recipient:
$mail_to = 'YOUR_EMAIL';
$mail_from = 'EMAIL_USED_FOR_SENDING';
$subject = 'Message from a site visitor '.$field_name;
//The email content:
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$mail_from."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
//Show a JSON message about the successful or unsuccessful sending of a message
if ($mail_status) {
$resArray= array('success' => true);
header('Content-Type: application/json');
echo json_encode($resArray);
} else {
$resArray= array('success' => false);
header('Content-Type: application/json');
echo json_encode($resArray);
}
?>
RECOMMENDATIONS
- EMAIL_USED_FOR_SENDING must be of the same domain as your website.
- Set up the local MTA (SMTP server) or sendmail to send emails.
Please read the following article. Please verify that you have set the proper Hostname for your sending server. Otherwise, your mail server may not accept emails. - OPTIONAL. You can create your server's matching A and Reverse DNS (PTR) records. Use the server Hostname like in this article.
For example: srv1.mydomain.com <-> 14.22.36.42. You can create the A record in the Admin panel of your domain registrar or DNS provider, and configure the PTR record in the Admin panel of your hosting provider. For more instructions, please refer to your provider's or registrar's documentation. - OPTIONAL. You can also configure the SPF record for your domain so emails sent with your server IP address are considered valid and do not become junk mail.
For more information about SPF records, please read this article. You can configure the SPF record in the Admin panel of your domain registrar or DNS provider.
Sample 2
The simplest script for sending emails using the Pear Mail Library is as follows. You can use your Gmail or any other account.
// Pear Mail Library
require_once "Mail.php";
//Specify the message recipient:
$from = '<YOUR_EMAIL@gmail.com>';
$to = '<YOUR_EMAIL@gmail.com>';
$field_name = $_POST['cf-name'];
$field_email = $_POST['cf-email'];
$field_message = $_POST['cf-message'];
$subject = 'Message from a site visitor '.$field_name;
//The email content:
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$body = $body_message;
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
// SMTP Google Settings
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'YOUR_EMAIL@gmail.com',
'password' => 'YOUR_PASSWORD'
));
$mail = $smtp->send($to, $headers, $body);
//Show a JavaScript message about the successful or unsuccessful sending a message
if (PEAR::isError($mail)) {
$resArray= array('success' => true);
header('Content-Type: application/json');
echo json_encode($resArray);
} else {
$resArray= array('success' => false);
header('Content-Type: application/json');
echo json_encode($resArray);
}
?>
The main disadvantage of this script is that it stores your Google account password in plain text.