Click here to Skip to main content
15,889,858 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

What I have tried:

**HTML Coding:**



Register your Restaurant here...




Name

Restaurant Name



Email

Phone



Location

Cuisine






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
Posted
Updated 18-Oct-18 2:23am
Comments
Richard MacCutchan 17-Oct-18 8:40am    
"Its not working."
Do you know that that is the most useless explanation it is possible to write?

It tells us absolutely nothing about your code or your problem. Please edit your question and explain where the problem occurs and full details of what is happening when you run it.
MadMyche 17-Oct-18 9:42am    
To add onto Richard's comment, it would be helpful to know what if any error messages you receive when running this.

1 solution

First, I sadly must inform your the $_POST has nothing to do with "posting an email message".

You need to see how it's done via samples as nothing in your tedious example, above, shows any clue as to how you expect to send the email and what system's supposed to handle it once it leaves you application.

Try: PHP 5 Mail Functions[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900