1 reply [Last post]
vin2785
Offline
Regular
West Yorkshire
Last seen: 12 years 33 weeks ago
West Yorkshire
Joined: 2008-12-12
Posts: 35
Points: 11

I have a problem with a PHP email script I've been using. It tends to submit blank data to my email address every time I enter the page it's coded into. All I remember was following a tutorial at college on how to do it and I haven't changed the script around much since. The script is as follows ( if anyone can suggest a better script than this then that would be appreciated ):

<?php
 
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
 
$to = '[email protected]';
$subject = "$subject";
$message = 
 
"Name: $name, 
Email: $email, 
Message: $message";
 
$headers = "From: $email";
 
 
mail($to, $subject, $message, $headers);
 
function VerifyForm(&$values, &$errors)
 
{
 
 
 
if (strlen($values['name']) < 1)
 
$errors['name'] = 'Please enter your name';
 
if (!ereg('.*@.*\..{2,4}', $values['email']))
 
$errors['email'] = 'Please enter a valid email';
 
if (strlen($values['message']) < 1)
 
$errors['message'] = 'Please enter a message';
 
return (count($errors) == 0);
 
}
 
function DisplayForm($values, $errors)
 
{
 
?>

Then the very last bit of code of the page

<?php
 
}
 
function ProcessForm($values)
 
{
 
 
 
echo ( "<div id=maincontent>Thank you, your email has been sent! <a href=\"javascript:history.back()\">Click here to go back</a></div>" );
 
 
 
}
 
if ($_SERVER['REQUEST_METHOD'] == 'POST')
 
{
 
$formValues = $_POST;
 
$formErrors = array();
 
if (!VerifyForm($formValues, $formErrors))
 
DisplayForm($formValues, $formErrors);
 
else
 
ProcessForm($formValues);
 
}
 
else
 
DisplayForm(null, null);
 
?>

Thanks in advance!

Tags:
vin2785
Offline
Regular
West Yorkshire
Last seen: 12 years 33 weeks ago
West Yorkshire
Joined: 2008-12-12
Posts: 35
Points: 11

admin/mods close/delete this

admin/mods close/delete this thread, i've just realised this script is full or problems and just replaced it with a better one.

thanks