Hi Guys, I am trying to send mail from HTML popup window with Name, restaurant name, MailID, Number,etc. Its not working. Below is the code. Can anyone help me please.
PHP Coding to send mail:
<?php
if(isset($_POST['m_email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "xxxxxx@gmail.com";
$email_subject = "New Registration";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.
";
echo $error."
";
echo "Please go back and fix these errors.
";
die();
}
// validation expected data exists
if(!isset($_POST['m_name']) ||
!isset($_POST['m_rname']) ||
!isset($_POST['m_email'])
!isset($_POST['m_phone'])
!isset($_POST['m_location'])
!isset($_POST['m_cuisine'])
) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$user_name = $_POST['m_name']; // required
$restaurant_name = $_POST['m_rname']; //required
$email_from = $_POST['m_email']; // required
$telephone = $_POST['m_phone']; // required
$location = $_POST['m_location']; // required
$cuisine = $_POST['m_cuisine']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.
';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$user_name)) {
$error_message .= 'The Name you entered does not appear to be valid.
';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "User Name: ".clean_string($user_name)."\n";
$email_message .= "Restaurant Name: ".clean_string($restaurant_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Contact No: ".clean_string($telephone)."\n";
$email_message .= "Location: ".clean_string($location)."\n";
$email_message .= "Cuisine: ".clean_string($cuisine)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
}
?>
And we have Java script to call the PHP cript from HTML page. Below is the script.
function regEmail(pg){
var request = $.ajax({
url: "./res_mail.php",
type: "POST",
data: {
action: "regEmail",
m_name:$("#m_name").val(),
m_rname:$("#m_rname").val(),
m_email:$("#m_email").val(),
m_phone:$("#m_phone").val(),
m_location:$("#m_location").val(),
m_cuisine:$("#m_cuisine").val()
},
//dataType: 'json'
dataType: 'html'
});
request.done(function (data) {
alert("Message Registered");
});
}
Using the above code its not triggering mail and its simply in the same page.
So can you any one help on this fix please