Jump to content

php mail script problem


staples27

Recommended Posts

hi

 

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.  The script is as follows ( if anyone can suggest a better script than this then that would be appreciated ):

 

<?php
error_reporting(0);

$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 for any help!

Link to comment
https://forums.phpfreaks.com/topic/160604-php-mail-script-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.