发送邮件 ajax,发送邮件使用PHP / AJAX从HTML表单(Send Email with PHP/AJAX F

我想发送的用户已经从一个HTML表单填写到我的电子邮件地址的信息。 从我的理解,这不能仅使用客户端代码做由于邮件是如何工作的性质,并建议使用PHP(与AJAX结合)来处理服务器端代码。 我也跟着指导这里 ,但我没有在我的电子邮件地址收到任何电子邮件。 我(使用XAMPP)之前,我部署我在我的客户的网络空间(GoDaddy的)代码我的机器上进行本地测试。 我想指出,我从来没有使用过PHP。

使用Javascript:

var data = "This is my email";

$.ajax({

type: "POST",

url: "email.php",

data: data,

dataType: "text"

});

PHP(email.php):

$to = "myself@hotmail.com";

$subject = "This is my email";

$message = $_REQUEST;

$send = mail($to, $subject, $message);

if(!$send){

die();

}

?>

Answer 1:

XAMPP没有电子邮件本身作为默认发送的东西。 您可以查看下面的链接;

PHP的邮件设置在XAMPP

如何启用XAMPP在本地使用PHP的mail()函数,这样我就可以测试我的邮件()脚本在本地,而无需上传到我的服务器?

Answer 2:

此时应更换$_REQUEST有$_REQUEST["data"]或这样的事情,因为$_REQUEST是一个数组。

Answer 3:

所有时间的页面被刷新。 下面是我的代码:

HTML 5:

JS:

$('form').bind('submit',function(){

$.ajax({

type : 'POST',

url : 'data/invite.php',

data : $(this).serialize(),

cache : false,

dataType: 'text',

success : function (serverResponse) { alert('mail sent successfully.'); },

error : function (jqXHR, textStatus, errorThrown) {alert('error sending mail');}

});

})

PHP:

$to = $_POST['mail'];

$name = 'Indusnet Technologies';

$subject = 'Think Recycle';

$text = 'Welcome to our site';

$message =' You received a mail from '.$name;

$message .='Text of the message : '.$text;

if(mail($to, $subject,$message)){

echo 'mail successful send';

}

else{

echo 'there’s some errors to send the mail, verify your server options';

}

?>

Answer 4:

var data = "This is my email";

$.ajax({

type: "POST",

url: "email.php",

data: data,

dataType: "text"

});

本规范768,16是这样的

var data = "This is my email";

$.ajax({

type: "POST",

url: "email.php",

data: {"data": data},

dataType: "text"

});

并获得代码或者通过$ _ POST [“数据”]或$ _REQUEST [“数据”]

Answer 5:

你或许应该返回false的形式。 尝试这个:

$('form').submit(function(){

$.ajax({

type : 'POST',

url : 'data/invite.php',

data : $(this).serialize(),

cache : false,

dataType: 'text',

success : function (serverResponse) { alert('mail sent successfully.'); },

error : function (jqXHR, textStatus, errorThrown) {alert('error sending mail');}

});

return false;

})

文章来源: Send Email with PHP/AJAX From HTML Form

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值