所以我有这个代码。对于一个网站,当管理员批准您成为用户时,他会单击此链接。它将帐户设置为活动状态,但我也想发送电子邮件。
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
require('includes/config.php');
//collect values from the url
$memberID = trim($_GET['x']);
$active = trim($_GET['y']);
//if id is number and the active token is not empty carry on
if(is_numeric($memberID) && !empty($active)){
//update users record set the active column to Yes where the memberID and active value match the ones provided in the array
$stmt = $db->prepare("UPDATE members SET active = 'Yes' WHERE memberID = :memberID AND active = :active");
$stmt->execute(array(
':memberID' => $memberID,
':active' => $active,
));
//if the row was updated redirect the user
if($stmt->rowCount() == 1){
//redirect to login page
$stmt = $db->prepare("SELECT email FROM members WHERE memberID = :memberID");
$stmt->bindparam(':memberID', $memberID);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_OBJ);
//send email
$to = $result->email;
$subject = "account actief";
$body = "Uw account op http://www.nol-groningen.nl is actief 'n'n
Met Vriendelijke groet,'n'n
Website Admin";
$additionalheaders = "From: <".SITEEMAIL.">'r'n";
$additionalheaders .= "Reply-To: $".SITEEMAIL."";
mail($to, $subject, $body, $additionalheaders);
header('Location: login.php?action=active');
exit;
} else {
echo "Your account could not be activated.";
}
}
?>
在我放入电子邮件内容之前,它确实有效,现在它只是进入空白页。有谁知道我如何修复它并让它发送确认电子邮件?
您在电子邮件代码运行之前重定向页面
向下移动header('Location: login.php?action=active');
并将其放在exit;
之前
header('Location: login.php?action=active');
exit;
像这样更改您的 if 语句
if($stmt->rowCount() == 1){
//redirect to login page
$stmt = $db->prepare("SELECT email FROM members WHERE memberID = :memberID");
$stmt->bindparam(':memberID', $memberID);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_OBJ);
//send email
$to = $result->email;
$subject = "account actief";
$body = "Uw account op http://www.nol-groningen.nl is actief 'n'n
Met Vriendelijke groet,'n'n
Website Admin";
$additionalheaders = "From: <".SITEEMAIL.">'r'n";
$additionalheaders .= "Reply-To: $".SITEEMAIL."";
mail($to, $subject, $body, $additionalheaders);
header('Location: login.php?action=active');
exit;
} else {
echo "Your account could not be activated.";
}
中没有PHP错误吗:
$stmt->execute(array(
':email' => $email,
//send email
$to = $email;
$subject = "account actief";
$body = "Uw account op http://www.nol-groningen.nl is actief 'n'n
[...]
));
您不应该检查答案并从执行中发送电子邮件吗?
脚本似乎不发送电子邮件的原因有多种。除非存在明显的语法错误,否则很难诊断这些内容。如果没有一个,您需要浏览下面的清单以找到您可能遇到的任何潜在陷阱。
回答 7 月 9 日 在 2:21 由约翰·孔德