Hello,
I have a contact.php form so people can email me via my website.
I have found code (from here) which uses a seperate EmailAddressValidator.php file to check the email address format.
The code to call it in my contact.php form is -
include('EmailAddressValidator.php');
$validator = new EmailAddressValidator;
if ($validator->check_email_address($email))
{
// Email address is technically valid
}
else
{
// Email not valid }
I am having trouble working out how to incorporate the above code into my own code shown below as I am not too hot with php! Can anyone help me out?
<?php
if (isset($_POST['submit']))
{
//require("validation.php");
$rules = array($name, $email, $message); // stores the validation rules
// standard form fields
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
/*Check required fields have been filled out*/
$mandate=array($name, $email); // Mandatory fields
if(empty($name))
$errors['name']="Please Enter Your Name!";
if(empty($email))
$errors['email']="Please Enter your Email Address!";
/*End of Check required fields have been filled out*/
/*Re-captcha code starts here - linked to recaptchalib.php*/
require_once('recaptchalib.php');
$privatekey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$errors['captcha']="The reCAPTCHA coded weren't entered correctly. Please try again.";
}
/*Re-captcha code ends here*/
// code to send email
if(count($errors)==0){
$to = 'me@me.com';
$subject = 'Email query from me.com';
$message = "Email sent from: $email \n $name has sent you a message:- \n $message";
$headers = 'From: "' . $name . '" <' . $email . '>';
'Reply-To: queries@me.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers) or exit('mail FAIL');
echo '<p>Thank you for emailing me!</p>';
}
else
{
echo '<p>Please re-check your form entries.</P>';
}
}
?>
<?php
if(!isset($_POST['submit']) || count($errors)){
?>
<form method="POST" action="<?php echo htmlentities($_SERVER['PHP_SELF']) ; ?>">
<p>Name</p>
<input type="text" name="name" size="19" value="<?php echo (isset($name)) ? $name : '';?>" class="textbox">
<?php
if(isset($errors['name'])) echo $errors['name'];
?>
<br>
<p>Email Address</p>
<input type="text" name="email" size="19" value="<?php echo (isset($email)) ? $email : '';?>" class="textbox">
<?php
if(isset($errors['email'])) echo $errors['email'];
?>
<br>
<p>Message</p>
<textarea rows="9" name="message" cols="30" class="textbox"><?php echo (isset($message)) ? $message: '';?></textarea>
<br>
<br>
<?php
require_once('recaptchalib.php');
$publickey = "xxxxxxxxxxxxxxxxxxxxxxxxx"; // you got this from the signup page
echo recaptcha_get_html($publickey);
if(isset($errors['captcha'])) echo $errors['captcha'];
?>
<input type="submit" value="Submit" name="submit" class="go">
</form>
<?php
}
?>