【问题标题】:Confirmation email not sending确认邮件未发送
【发布时间】:2015-02-02 04:17:35
【问题描述】:

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

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

}
?>

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

【问题讨论】:

  • 貌似是黑名单的事情
  • 尝试回显 $email;检查天气是否有一些邮件在变量中。

标签: php email admin activation


【解决方案1】:

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

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

【讨论】:

  • 我已经更新了我的答案,现在检查一下,确保你在页面上获得了 memberID。
  • 在激活部分有效。不适用于邮寄部分
【解决方案2】:

中没有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
    [...]
));

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

【讨论】:

  • 我看到它不起作用。它通过有效的 beta 文件夹发送给我。所以这段代码实际上不起作用
  • 好的,因为我单独测试了代码,它在我的服务器上运行。应该是邮件服务器配置。
  • 您可以访问您的服务器 php.ini 吗?如果不检查线程:using-mail-with-no-access-to-php-ini
  • 不,我不知道。至少我不知道我怎么能找到它
【解决方案3】:

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

answered Jul 9 at 2:21 by John Conde

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    相关资源
    最近更新 更多