Forum Moderators: coopster
Below is my PHP script, hope someone can help.
Thanx
<?php
$result = "Beechwood Homes website enquiry form\r\n\r\n";
$result .= "Developments: " . $Developments . "\r\n";
$result .= "Name: " . $Fname . "\r\n";
$result .= "Last Name: " . $Lname . "\r\n";
$result .= "Email: " . $Email . "\r\n";
$result .= "Tel: " . $Phone . "\r\n";
$result .= "Address: " . $Address . "\r\n";
$result .= "Address2: " . $Address2 . "\r\n";
$result .= "Town: " . $Town . "\r\n";
$result .= "County: " . $County . "\r\n";
$result .= "Postcode: " . $Postcode . "\r\n";
$result .= "Country: " . $Country . "\r\n";
$result .= "Min property price: " . $Minprice . "\r\n";
$result .= "Max property price: " . $Maxprice . "\r\n";
$result .= "Do you have a house to sell?: " . $Selling . "\r\n";
$result .= "How did you find this Web Site?: " . $Source . "\r\n";
$result .= "Please tick the box if you would like to be added to our mailing list: " . $Mailinglist . "\r\n";
if ($Email) {
$headers = "From: $Fname <$Email>\r\n\r\n";
} else {
$headers = "From: No Name given <anonymous@yourserver.com>\r\n\r\n";
}
$sendit = mail("my@domain.co.uk", "Website contact form", $result, $headers) or die("Something went wrong");
echo "<meta http-equiv='refresh' content='0; url=thank.htm'>";
die;
?>
To make fields 'required', you need to check that the fields have something in them.
For example -
$errorString = '';
if(sizeof($_POST)==0){
$errorString .= 'No form data submitted<br />';
die($errorString);
}
Hope that helps you on the way
:)
<?php
// Receiving variables
@$Developments = addslashes($_POST['Developments']);
@$Fname = addslashes($_POST['Fname']);
@$Lname = addslashes($_POST['Lname']);
@$Email = addslashes($_POST['Email']);
@$Phone = addslashes($_POST['Phone']);
@$Address = addslashes($_POST['Address']);
@$Address2 = addslashes($_POST['Address2']);
@$Town = addslashes($_POST['Town']);
@$County = addslashes($_POST['County']);
@$Postcode = addslashes($_POST['Postcode']);
@$Country = addslashes($_POST['Country']);
@$Minprice = addslashes($_POST['Minprice']);
@$Maxprice = addslashes($_POST['Maxprice']);
@$Selling = addslashes($_POST['Selling']);
@$Source = addslashes($_POST['Source']);
@$Mailinglist = addslashes($_POST['Mailinglist']);
// Validation
if (strlen($Fname) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid First name</font></p>");
}
if (strlen($Lname) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid Last name</font></p>");
}
if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $Email))
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}
if (strlen($Address) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid address</font></p>");
}
if (strlen($Postcode) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid postcode</font></p>");
}
//Sending Email to form owner
$pfw_header = "From: $Email\n"
. "Reply-To: $Email\n";
$pfw_subject = "Beechwood Homes website form";
$pfw_email_to = "shush@freshlemon.co.uk";
$pfw_message = "Developments: $Developments\n"
. "Fname: $Fname\n"
. "Lname: $Lname\n"
. "Email: $Email\n"
. "Phone: $Phone\n"
. "Address: $Address\n"
. "Address2: $Address2\n"
. "Town: $Town\n"
. "County: $County\n"
. "Postcode: $Postcode\n"
. "Country: $Country\n"
. "Minprice: $Minprice\n"
. "Maxprice: $Maxprice\n"
. "Selling: $Selling\n"
. "Source: $Source\n"
. "Mailinglist: $Mailinglist\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
//Sending auto respond Email to visitor
$pfw_header = "From: shush@freshlemon.co.uk\n"
. "Reply-To: shush@freshlemon.co.uk\n";
$pfw_subject = "Confirmation of your enquiry to Beechwood Homes";
$pfw_email_to = "$Email";
$pfw_message = "Thank you $Fname";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
//saving record in a text file
$pfw_file_name = "form-results.csv";
$pfw_first_raw = "Developments,Fname,Lname,Email,Phone,Address,Address2,Town,County,Postcode,Country,Minprice,Maxprice,Selling,Source,Mailinglist\r\n";
$pfw_values = "$Developments,$Fname,$Lname,$Email,$Phone,$Address,$Address2,$Town,$County,$Postcode,$Country,$Minprice,$Maxprice,$Selling,$Source,$Mailinglist\r\n";
$pfw_is_first_row = false;
if(!file_exists($pfw_file_name))
{
$pfw_is_first_row = true ;
}
if (!$pfw_handle = fopen($pfw_file_name, 'a+')) {
die("Cannot open file ($pfw_file_name)");
exit;
}
if ($pfw_is_first_row)
{
if (fwrite($pfw_handle, $pfw_first_raw ) === FALSE) {
die("Cannot write to file ($pfw_filename)");
exit;
}
}
if (fwrite($pfw_handle, $pfw_values) === FALSE) {
die("Cannot write to file ($pfw_filename)");
exit;
}
fclose($pfw_handle);
echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>Thank you</font></p>");
?>
Lose the @ signs - those suppress error messages, which you want to see at this point. After you know your script is bug-free, you can use error_reporting() [us3.php.net].
There's not really anything wrong with doing this:
if (strlen($Fname) == 0 )
But it's simpler and faster to to do this:
if($Fname == '')
What's the error you're getting? If it mentions a line number, please also point out which line it is.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
[edited by: coopster at 8:03 pm (utc) on Mar. 10, 2008]
[edit reason] generalized email [/edit]
If you'll report your results I/we can help. What happens if you comment the whole bloody thing and add an echo line:
<?php
echo "Hello.";
/*
// All the stuff you've posted
*/
?>
Does the script execute and produce the word in your browser or does it have an internal server error?
1. If there's an error, you've got permission problems. Try changing it to 644 on the server with a file manager or ftp program. Or try a brand new file.
2. If there's no error, move the /* down a few lines and execute it again. Keep going until the error reappears.
Report back after your experiments.