gpt4 book ai didi

javascript - 电子邮件未发送。 ajax发送的值

转载 作者:行者123 更新时间:2023-11-28 00:04:02 25 4
gpt4 key购买 nike

我正在通过 AJAX 调用获取值并发送隐藏字段值,然后执行查询以更新数据库中的某些内容。第一个初始查询找到 id 和其他 $_POST信息和效果都很好。但是我的电子邮件没有发送。我的警报错误消息没有显示任何内容,但正在显示(它是一个空白警报)。

有人看到我如何尝试发送到我的电子邮件或我如何在我的电子邮件中获取它不会发送的值有任何问题吗?

隐藏输入字段..

<input type="hidden" value="<?php echo $approved_id; ?>" id="approved_id" name="id" />
<input type="hidden" value="<?php echo $approved_firstname; ?>" id="approved_firstname" name="firstname" />
<input type="hidden" value="<?php echo $approved_lastname; ?>" id="approved_lastname" name="lastname" />
<input type="hidden" value="<?php echo $approved_username; ?>" id="approved_username" name="username" />
<input type="hidden" value="<?php echo $approved_email; ?>" id="approved_email" name="email" />

ajax调用..

$(document).ready(function () {

$('#update_group').on('submit', function (event) {
event.preventDefault();
$.ajax({
url: 'user_group_update.php',
type: 'POST',
data: {
id: $("#approved_id").val(), //id
firstname: $("#approved_firstname").val(), //firstname
lastname: $("#approved_lastname").val(), //lastname
username: $("#approved_username").val(), //username
email: $("#approved_email").val(), //email
// update_group: $("#group_id").val() //group level
update_group: $(this).find( "#group_id option:selected" ).val()
},
success: function (data) {
//do something with the data that got returned
$(".group_success").fadeIn();
$(".group_success").show();
$('.group_success').html('User Permission Level Changed!');
$('.group_success').delay(5000).fadeOut(400);
alert(data);
},
error: function(jqXHR, textStatus,errorThrown )
{
// alert on an http error
alert( textStatus + errorThrown );
}
});
return false;
});
});

用户组更新.php

<?php
ini_set('log_errors', 1);
ini_set('error_log', __DIR__ . DIRECTORY_SEPARATOR . 'error.log');
error_reporting(E_ALL);
require_once 'core/init.php';

$approved_id = $_POST['id'];
//test - delete if it doesn't work
$approved_firstname = $_POST['firstname'];
$approved_lastname = $_POST['lastname'];
$approved_username = $_POST['username'];
$approved_email = $_POST['email'];
$change_group = $_POST['update_group'];

$con = mysqli_connect("localhost","","","");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$stmt = $con->prepare("UPDATE users,user_requests SET users.group=?, user_requests.group=? WHERE users.id=? AND user_requests.user_id=?");
if ( !$stmt || $con->error ) {
// Check Errors for prepare
die('User Group update prepare() failed: ' . htmlspecialchars($con->error));
}
if(!$stmt->bind_param('iiii', $change_group, $change_group, $approved_id, $approved_id)) {
// Check errors for binding parameters
die('User Group update bind_param() failed: ' . htmlspecialchars($stmt->error));
}
if(!$stmt->execute()) {
die('User Group update execute() failed: ' . htmlspecialchars($stmt->error));
}

//test
$email_stmt = $con->prepare("SELECT * FROM users WHERE id=?");
if ( !$email_stmt || $con->error ) {
// Check Errors for prepare
die('User email prepare() failed: ' . htmlspecialchars($con->error));
}
/*if(!$email_stmt->bind_param('ii', $change_group, $approved_id)) {
// Check errors for binding parameters
die('User email bind_param() failed: ' . htmlspecialchars($stmt->error));
}
if(!$email_stmt->execute()) {
die('User email execute() failed: ' . htmlspecialchars($stmt->error));*/
/*
$row = mysqli_fetch_assoc($$email_stmt);
$pending_id = $_POST['id'];
$group_firstname = $row['firstname'];
$group_lastname = $row['lastname'];
$group_username = $row['username'];
$group_email = $row['email'];
$group_email = $row['group'];*/

$to = $approved_email;
$subject = 'There is a new user request to join the Sunday Funday League';
$message = '
<html>
<head>
<title>New SFL User Request</title>
</head>
<body>
<p>Hi '.$approved_firstname.',</p><br>
<p>Your Sunday Funday League Account has been accepted. You have been added to the group. To sign in, click this link
http://sundayfundayleague.com . </p><br>
<p>Thank you,</p>
<p>Administration</p>
</body>
</html>
';

$from = "user-requests@sundayfundayleague.com";
$Bcc = "user-requests-confirm@sundayfundayleague.com";

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
//$headers .= 'To: ' .$to;//. "\r\n";
$headers .= 'From: ' .$from; "\r\n";
$headers .= 'Bcc: '.$Bcc; "\r\n";

// Send the email
mail($to,$subject,$message,$headers);

最佳答案

PHP 中的 mail() 函数将返回 truefalse,因此您将无法在客户端。

但是,当 mail() 失败时,您可以使用 error_get_last() here .

由于 mail() 函数返回 truefalse,您将能够创建一个简单的 if 语句来检查它是否成功:

if(mail($to,$subject,$message,$headers)){
// success
} else {
print_r(error_get_last());
}

尝试此操作以获取有关后台发生的情况的更多信息。

关于javascript - 电子邮件未发送。 ajax发送的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31518247/

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