Creating a form >> << Introduction
The zip file you downloaded should contain a single directory called php
and a single file called index.php
.
The index.php
file simply contains an example of how to integrate
this script into your own web page.
Inside of the php
directory there will be a directory called SimpleContactForm
which contains this script's files and (if you have downloaded the PHPMailer version) another directory
called PHPMailer
which is the library used to send emails.
The first thing to do is to copy the entire php
directory into your website's root directory
and the example index.php
file can be discarded.
You should also make sure that the web page you will be inserting the form into has a .php
extension.
The next step is to adjust the default configuration which is stored in this file :
php/SimpleContactForm/SimpleContactForm.configuration.php
The configuration file has the following format :
1 | $config [ 'SETTING-NAME' ] = SETTING-VALUE; |
You will only need to edit the part that says SETTING-VALUE
.
If a setting value is wrapped in single quotes always make sure that you do not delete them
if you make changes to the value.
First you will need to configure the name of the website.
It will look something like this :
1 2 | $config [ 'website' ] = '__WEBSITE__' ; $config [ 'useTextCaptcha' ] = false ; |
Change the part that says __WEBSITE__
to the name of your website.
This setting will be used to set the email subject and it will also be inserted (when you are using the
default mail template) as a heading into the emails sent from your forms.
You can also change false
on the second line to true
if
you would prefer for some reason (or if your server does not support the php GD extension),
to use a text-based captcha instead of the image based one; note that this text-based captcha is probably
not very secure at all.
Next you will configure how the emails will be sent. They can either be sent through your own SMTP or using
the PHP mail()
function.
If you do not have access to, or do not want to use an SMTP server then change the value of the first option
useSmtpServer
from true
to false
.
Otherwise leave the first line as is and fill in your server details on the lines below that.
1 2 3 4 5 | $config [ 'useSmtpServer' ] = true ; $config [ 'smtpServer' ] = 'mail.domain.com' ; $config [ 'smtpUsername' ] = 'user@domain.com' ; $config [ 'smtpPassword' ] = 'password' ; $config [ 'smtpPort' ] = 25; |
If you do not know your server's SMTP mail server details you should be abe to get them from your server host.
These settings are only needed if you have download the PHPMailer version.
The next two lines contain the from and to addresses of the email.
The to
address must be set to the email that you want to recieve the emails
sent be the contact forms.
Just change the parts that say user@domain.com
and
recipient@domain.com
to the correct values.
1 2 | $config [ 'from' ] = array ( 'user@domain.com' , $config [ 'website' ] . ' Enquiry Form' ); $config [ 'to' ] = array ( 'recipient@domain.com' , $config [ 'website' ]); |
You may specify more than one to
address if you would like the contact form to be sent to multiple
people.
The list has the following format :
EMAIL-ADDRESS
, DISPLAY-NAME
1 2 3 4 | // An example of multiple recipients : $config [ 'to' ] = array ( 'recipient1@domain.com' , 'Recipient1 Name' , 'recipient2@domain.com' , 'Recipient2 Name' , 'recipient2@domain.com' , 'Recipient2 Name' ); |
The strings
option holds all the text used by the script.
This allows you to easily translate or change any text displayed by the script.
1 2 3 4 | $config [ 'strings' ] = array ( 'NAME' => 'TEXT' , ... ); |
For a description of each string visit the configuration file reference
The remaining options will be discussed later on in this tutorial.
You can also visit the
configuration file reference
for a description of all the options found in this file.