如何从HTML弹出窗口发送邮件 [英] How to send mail from HTML popup
问题描述
嗨大家好,我正在尝试从HTML弹出窗口发送带有姓名,餐馆名称,MailID,号码等的邮件。它不起作用。下面是代码。有人可以帮我吗。
我尝试过:
** HTML编码:**
注册你的餐厅在这里...
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...
PHP编码发送邮件:
<?php
if(isset($ _ POST ['m_email'])){
//根据需要编辑以下两条线
$ email_to =xxxxxx@gmail.com;
$ email_subject =新注册;
功能死亡($ error){
//你的错误代码可以到这里
echo我们非常抱歉,但是您提交的表单中发现了错误。 ;
echo这些错误出现在下面。
;
echo $ error。
;
echo请回去修复这些错误。
;
die();
}
//验证预期数据存在
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'])
){
死亡('我们很抱歉,但您提交的表单似乎有问题。');
}
$ user_name = $ _POST ['m_name']; //要求
$ restaurant_name = $ _POST ['m_rname']; //要求
$ email_from = $ _POST [ m_email]; //需要
$电话= $ _POST [ m_phone]; //必需
$ location = $ _POST ['m_location']; //必需
$ cuisine = $ _POST ['m_cuisine']; //必填
$ 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。='您输入的电子邮件地址似乎无效。
';
}
$ string_exp =/ ^ [A-Za-z .'-] + $ /;
if(!preg_match($ string_exp,$ user_name)){
$ error_message。='您输入的名称似乎无效。
';
}
if(strlen($ error_message)> 0){
死了($ error_message);
}
$ email_message =表格详情如下。\ nn \ n;
函数clean_string($ string){
$ bad = array(co ntent-type,bcc:,to:,cc:,href);
返回str_replace($ bad,,$ string);
}
$ email_message。=用户名:。makean_string($ user_name)。\ n;
$ email_message。=餐馆名称:。cleanantring($ restaurant_name)。\ n;
$ email_message。 =电子邮件:。。makean_string($ email_from)。\ n;
$ email_message。=联系号码:。cleanantring($ telephone)。\ n;
$ email_message。=位置:。。chan_string($ location)。\ n;
$ email_message。=菜肴:。cleanantring($ cuisine)。 \ n;
//创建电子邮件标题
$ headers ='发件人:'。$ email_from。\\\\ n。
'回复:'。$ email_from。\ r \ n。
'X-Mailer:PHP /'。 phpversion();
@mail($ email_to,$ email_subject,$ email_message,$ headers);
}
?>
我们有Java脚本从HTML页面调用PHP cript。下面是脚本。
函数regEmail(页码){
var request = $ .ajax( {
url:。/ res_mail.php,
类型:POST,
数据:{
动作: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(函数(数据){
alert(消息注册);
});
} < br $> b $ b
使用上面的代码,它不会触发邮件,只是在同一页面上。
你能这样吗?请帮忙解决此问题
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
推荐答案
_POST ['m_email'])){
//根据需要编辑2条线
_POST['m_email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
email_to =xxxxxx@gmail.com;
email_to = "xxxxxx@gmail.com";
email_subject =新注册;
函数死亡(
email_subject = "New Registration";
function died(
这篇关于如何从HTML弹出窗口发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!