The fasthosts help text:
The sendmail script
Now we have a form that sends information to a script, we need to create a script to send the email. In this example, we will name the script sendmail.php as this is the address the our form is submitting the data to.
In order to send an email, we need certain information (variables), so lets set them first.
<?php
$email_to = "
you@yourdomain.com";
$name = $_POST["name"];
$email_from = $_POST["email"];
$message = $_POST["message"];
$email_subject = "Feedback from website";
$headers =
"From: $email_from .\n";
"Reply-To: $email_from .\n";
The code above sets the email address you will send your email to and gets the users' name, email address, and message from the previous form. It also sets the variables that contain the email subject, and headers to specify the from and reply to email addresses.
Now lets build the message of the email with the users' name and comments.
$message = "Name: ". $name . "\r\nMessage: " . $message;
Finally, let's send the email. If the email is sent we will go to a thank you page, if there is an error we will display a brief message.
ini_set("sendmail_from", $email_from);
$sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email_from);
if ($sent)
{
header("Location:
http://www.yourdomain.com/thankyou.html");
} else {
echo "There has been an error sending your comments. Please try later.";
}
?>
This script does not have any validation or error checking, so it is not recommended that you copy it directly to your website, however, it does show the basics of sending email from our webservers, and can be used as a framework for your own scripts.
Using third party scripts to send email
Third party scripts using sendmail will also work on Fasthosts servers, although some will need slight changes made in order to work correctly.
If you are using a third party script to send email remember to set the sendmail_from variable (using ini_set('sendmail_from',email_from)), add the fifth -f parameter, and send the email either to, or from, a Fasthosts hosted email address.