I can’t say I haven’t tried to do this myself but have just failed. Having searched contact form after contact form, I have almost achieved the most simple one of all.
It e mails the details, but the one problem is have clicked submit you get a blank page. You end up on www.c5d.co.uk/send_contact.php
This is the change of address page: www.c5d.co.uk/addresschange.php and this is what I have put in there. I don’t know if the javascript is necessary but it was on the free form.
<form method="POST" name="contactform" action="changeofaddress.php">
<p>
<label for='name'>Your Name:</label> <br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Email Address:</label> <br>
<input type="text" name="email"> <br>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message"></textarea>
</p>
<input type="submit" value="Submit"><br>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator = new Validator("contactform");
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
</script>
As instructed, I then created a page call www.c5d.co.uk/changeofaddress.php with this code.
<?php
$errors = '';
$myemail = 'antonylambert@c5d.co.uk';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\
Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\
Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\
Name: $name \
Email: $email_address \
Message \
$message";
$headers = "From: $myemail\
";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('http://www.c5d.co.uk/changeofaddress.php');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Change of Address</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
The message comes through OK, but the success page has the following across the middle
Warning: Cannot modify header information - headers already sent by (output started at /websites/123reg/LinuxPackage21/c5/d_/co/c5d.co.uk/public_html/changeofaddress.php:8) in /websites/123reg/LinuxPackage21/c5/d_/co/c5d.co.uk/public_html/changeofaddress.php on line 72
What I want it to say is " Thanks for submitting your information"
It e mails the details, but the one problem is have clicked submit you get a blank page. You end up on www.c5d.co.uk/send_contact.php
This is the change of address page: www.c5d.co.uk/addresschange.php and this is what I have put in there. I don’t know if the javascript is necessary but it was on the free form.
Where am I going wrong?
Antony