Mailing form
Posted: Wed Dec 14, 2011 4:11 am
Hello, this is my code:
It's for this mailing form (http://coreyworrell.com/blog/article/cr ... -ajax-form)
But it doesn't send mails.. What I am doing wrong?
Code: Select all
<?php
$name = $_REQUEST['name'] ;
$fam = $_REQUEST['fam'] ;
$email = $_REQUEST['email'] ;
$country = $_REQUEST['country'] ;
$tel = $_REQUEST['tel'] ;
$city = $_REQUEST['city'] ;
$message = $_REQUEST['message'] ;
$message = "
name: $name \n
last-name: $fam \n
mail: $email \n
country: $country \n
city: $city \n
phone: $tel \n
message: $message \n";
if($result == 'success')
{
mail( "my_mail@mail.com", "New message",
$message, "From: $email");
}
if ( ! empty($_POST['contact']))
{
$valid = array
(
'name' => array('/(.+){2,}/', 'Error.'),
'fam' => array('/(.+){2,}/', 'Error.'),
'tel' => array('/(.+){5,}/', 'Error'),
'city' => array('/(.+){3,}/', 'Error'),
'email' => array('/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?$/iD', 'Error.'),
'message' => array('/(.+){10,}/', 'Error.'),
);
$errors = array();
foreach ($valid as $field => $data)
{
$regex = $data[0];
$message = $data[1];
$input = trim($_POST[$field]);
if (empty($input) OR ! preg_match($regex, $input))
{
$errors += array($field => $message);
}
}
$result = empty($errors) ? 'success' : 'errors';
echo json_encode(array
(
'result' => $result,
'errors' => $errors,
));
exit;
}
?>But it doesn't send mails.. What I am doing wrong?