确认电子邮件未发送

时间:2014-12-04 10:17:53

标签: php email admin activation

所以我有这个代码。 对于某个网站,当管理员批准您成为用户时,他会点击此链接。它会将帐户设置为活动,但我也想要发送电子邮件。

<?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."; 
}

}
?>

在我把电子邮件放进去之前它确实有效,现在它只是一个空白页面。有谁知道我如何解决它并让它发送确认电子邮件?

3 个答案:

答案 0 :(得分:2)

您在电子邮件代码运行之前重定向页面

向下移动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."; 
}

答案 1 :(得分:0)

不存在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
    [...]
));

你不应该检查答案并发送电子邮件执行吗?

答案 2 :(得分:0)

  

您的脚本似乎没有发送电子邮件的原因有多种。除非出现明显的语法错误,否则很难诊断这些事情。如果没有,您需要查看下面的清单,找出您可能遇到的任何潜在陷阱。

answered Jul 9 at 2:21 by John Conde