Example Scripts

PLEASE NOTE: Biz-hosting Technical Support does not provide scripting support. However we have provided the following articles which cover some common scripting problems.

Choose an article below:

EXAMPLE: 'Form to mail' script using Jmail
EXAMPLE: 'Form to mail' script using PHP
EXAMPLE: 'Form to mail' script using Jmail

Summary

This article provides an example of how to use Dimac w3 JMail to pick up input from a submitted form and send an email to the intended recipient via ASP (Active Server Pages).

For further information on JMail, go to www.dimac.net

Example

First of all, you need a form to receive the data:

e.g. JmailForm.asp

Next, you need a script to read the form, extract the information, and create the email:

e.g. SendMail.asp

Note: Do not forget to clear the mail object at the end of the script.

Warning: The JMail component use SMTP, and you should be aware that all Biz-hostings' SMTP servers have filters which ensure that either the to or from address relates to a domain hosted by Fasthosts. An email which is not sent TO or FROM a domain hosted by Fasthosts, will be rejected by Fasthosts' SMTP servers.

EXAMPLE: 'Form to mail' script using PHP

Summary

This article gives an example of how to use a PHP script to take input from a feedback form and send it to you in an email message.

Note: PHP pages will not work if placed in cgi-bin. They need to be in the htdocs directory.

Example

The following example uses a PHP script to take input from a feedback form and send it to you in an email message.

First of all, you need a form to receive the data, e.g. feedback.html:

feedback.html

The form asks the visitor for his/her email address (via the email field above) and message (via the message field above), and invites the visitor to click a button to submit the contents of the form. When the form is submitted, it is 'posted' to a script named sendmail.php. Next, you need to create the sendmail.php script, using the facilities available in PHP, e.g.

mail( "yourname@yourdomain.com", "Feedback Form

results",$message, "From: $email", "-fuser@userdomain.com" );

header( "Location: http://www.yourdomain.com/thankyou.html" );

Quick tip: If you are using PHP on a Windows server use the PHP mail function and set the mail from using the following line of code - replacing email@mydomain with the correct domain name.

ini_set("sendmail_from", " email@mydomain ");

When the form is submitted to sendmail.php, the contents of the email field in the form are inserted into a PHP variable called $email, and the contents of the message field are inserted into the variable $message. The script calls a special function called mail, which takes care of the actual dispatch. The first parameter to mail is the address to which you want the form contents sent, in this case your own email address. The second parameter is the subject of the email message, the third is the content of the message, and the fourth is the "From" header so that you know who the sender is, and can reply.

In order for the script to work, you need to specify, via a fifth -f parameter, the domain from which the mail is being sent. The PHP component uses SMTP, and all SMTP servers have filters which ensure that the data returned by either the first or fifth mail parameter relates to one of your domains hosted by Fasthosts. The final part of the script thanks the visitor for the message. This is done by sending an HTTP header back to the visitor's browser telling it to load a file called thankyou.html from your domain. The /header/function allows you to send any HTTP header back to the browser.

Note: The script has to be enclosed within the “” tags because the PHP processor treats all input as HTML code unless otherwise specified. On some systems, you may need to use “” as the opening and closing tags to get the script to work.