gpt4 book ai didi

php - 使用 jquery 发送电子邮件不起作用 :PHP

转载 作者:行者123 更新时间:2023-11-29 22:36:59 25 4
gpt4 key购买 nike

据我所知,此脚本在 Chrome 和 IE 中运行良好。它在 Firefox 中无法正常工作。 (不能保证一切都完美运行——偶尔会有一封电子邮件没有通过,但我们无法重现该错误。)

编辑:现在看来,在 Chrome 和 Firefox 中,电子邮件不会在第一次尝试时发送,但如果我点击 PayPal 的后退按钮并提交再次发送。

我认为问题可能是 AdBlock Plus 以某种方式禁用了脚本。在页面上禁用了 ABP,它发送了......但是在刷新页面并尝试再次发送后,它又回到了不工作。

此注册表单应该发送一封包含大量表单数据的电子邮件,更改适当的输入以准备将用户注册的内容提交给 PayPal,然后将用户重定向到 PayPal 以单独处理付款。重定向到 PayPal 总是完美地发生,购物车中有适当的项目。

此代码位于 HTML 文件的头部。 (它曾经使用我自己的一个缩小的 jQuery 文件,所以在搜索错误时我尝试链接到这个 - 没有解决问题。)

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script type="text/javascript" src="[myscripts].js"></script>

表格开始:

<form id="[myformname]" name="[myformname]" method="post" action="">

[myscripts].js 包含这个:

$(function() {  
$('.error').hide();
$(".button").click(function() {

// many lines pulling input from form, generally of the type:
var firstname = $("input#firstname").val();
// as well as
var subscribe = $("input#subscribe").is(':checked');

// simple validation code for now, here is a generalized version
if (firstname == ''){
$('p#errors').html("Error: First name is required.");
$("p#errors").show();
return false;
}
else if (lastname == ''){
$('p#errors').html("Error: Last name is required.");
$("p#errors").show();
return false;
}
else {
$("p#errors").hide();
}


fixFields(); // this does the adjustment for PayPal
// checked checkboxes -> item_name_1, amount_1, etc.

// in the real code, submitString is very long
var submitString = 'firstname='+firstname+'&lastname='+lastname+'&email='+email+'&subscribe='+subscribe; // etc.

$.ajax({
type: "POST",
url: "register.php",
data: submitString,
success: function() {
return false;
}
});

submitForm(); // resets action to PayPal link, resubmits

});
});

如果相关,这里是之前在 [myscripts].js 中定义的 submitForm 方法:

function submitForm(){
var form_url = $("#[myformname]").attr("action");
//changing the action
$("#[myformname]").attr("action","https://www.paypal.com/cgi-bin/webscr");
//submit the form
$("#[myformname]").submit();
return true;
}

这是register.php:

<?php
$to = "[example1]@gmail.com,[example2]@gmail.com";
$subject = "New Registration";
$headers = "From: webmaster@[mysite.com]";

// shortened for readability's sake
$name = $_POST['firstname']." ".$_POST['lastname'];

$body = "INFORMATION\n".$name."\n".$_POST['email'].", Subscribe: ".$_POST['subscribe'];

$body = $body."\nSELECTIONS\n";
if ( $_POST['option1']=="true" ) {
$body = $body."Option 1 Name\n Details Line 1\n Details Line 2\n";
}
if ( $_POST['option2']=="true" ) {
$body = $body."Option 2 Name\n Details Line 1\n Details Line 2\n";
}

mail($to, $subject, $body, $headers);

?>

抱歉,如果这篇文章长得离谱。我是一名编程爱好者,对我在这里使用的许多语言都很陌生,所以我想尽可能清楚。提前感谢您的任何建议。

最佳答案

在将表单提交到 paypal 之前,您可能没有给它足够的机会通过 AJAX 发送表单,请尝试将 submitForm() 函数移动到 success 中AJAX 功能。

关于php - 使用 jquery 发送电子邮件不起作用 :PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4648090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com