【问题标题】:php $link in HTML emailsHTML 电子邮件中的 php $link
【发布时间】:2014-08-26 07:06:45
【问题描述】:

嘿,我已经开始制作用于密码重置和注册验证的 html 电子邮件。但我在这方面做得很好。如果可能的话,有人可以帮我完成它。我希望它从数据库中获取密码重置哈希,并从会话中获取用户名。我也很乐意提供更多代码。由于需要工作的 php 代码,我不能使用“JSFiddle”。谢谢约书亚

    <?php require_once 'application/config/autoload.php'; 

        $host= DB_HOST;
        $username= DB_USER;;
        $password= DB_PASS;
        $db_name= DB_NAME;
        $tbl_name= DB_TABLE;

    error_reporting(0);

    mysql_connect($host, $username, $password)or die("cannot connect");
    mysql_select_db($db_name)or die("cannot select DB");
    $user_name = Session::get('user_name');
    $sth = $this->db->prepare("SELECT user_id,
                                              user_name,
                                              user_email,
                                              user_password_hash
                                       FROM   users
                                       WHERE  (user_name = :user_name OR user_email = :user_name)
                                              AND user_provider_type = :provider_type");
            // DEFAULT is the marker for "normal" accounts (that have a password etc.)
            // There are other types of accounts that don't have passwords etc. (FACEBOOK)
            $sth->execute(array(':user_name' => $_POST['user_name'], ':provider_type' => 'DEFAULT'));
            $count =  $sth->rowCount();
            // if there's NOT one result
            if ($count != 0) {
                // was FEEDBACK_USER_DOES_NOT_EXIST before, but has changed to FEEDBACK_LOGIN_FAILED
                // to prevent potential attackers showing if the user exists
                $_SESSION["feedback_negative"][] = "bad";
                return false;

            }else{

    $link = EMAIL_PASSWORD_RESET_URL . '/' . urlencode($user_name) . '/' . urlencode($user_password_reset_hash);
    echo "
    <html>
    <head>
    <style>
    body {
        background-color: #fff;
        font-family: Arial;
        font-size: 14px;
        color: #000;
        padding: 0;
        margin: 15;
    }
    h1 {
        font-size: 40px;
    }
    h2 {
        font-size: 20px;
    }
    </style>

    <div>
        <img src='logo.min.png' align='left'></p>
        <h1 align='right'>Teacher Help</h1>
        <h2 align='right'>Verify Email<br></h2>
        <p><?php echo $link ?></p>
    </div>
    </head>
    </html>"
                return false;?>

更新

<?php require_once 'application/config/autoload.php'; 

    $host= DB_HOST;
    $username= DB_USER;;
    $password= DB_PASS;
    $db_name= DB_NAME;
    $tbl_name= DB_TABLE;

error_reporting(0);

mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");
$user_name = Session::get('user_name');
$sth = $this->db->prepare("SELECT user_id,
                                          user_name,
                                          user_email,
                                          user_password_hash
                                   FROM   users
                                   WHERE  (user_name = :user_name OR user_email = :user_name)
                                          AND user_provider_type = :provider_type");
        // DEFAULT is the marker for "normal" accounts (that have a password etc.)
        // There are other types of accounts that don't have passwords etc. (FACEBOOK)
        $sth->execute(array(':user_name' => $_POST['user_name'], ':provider_type' => 'DEFAULT'));
        $count =  $sth->rowCount();
        // if there's NOT one result
        if ($count != 1) {
            // was FEEDBACK_USER_DOES_NOT_EXIST before, but has changed to FEEDBACK_LOGIN_FAILED
            // to prevent potential attackers showing if the user exists
            $_SESSION["feedback_negative"][] = "bad";
            return false;

        }else{

$link = EMAIL_PASSWORD_RESET_URL . '/' . urlencode($user_name) . '/' . urlencode($user_password_reset_hash);
echo "
<html>
<head>
<style>
body {
    background-color: #fff;
    font-family: Arial;
    font-size: 14px;
    color: #000;
    padding: 0;
    margin: 15;
}
h1 {
    font-size: 40px;
}
h2 {
    font-size: 20px;
}
</style>

<div>
    <img src='logo.min.png' align='left'></p>
    <h1 align='right'>Teacher Help</h1>
    <h2 align='right'>Verify Email<br></h2>
    <p>$link</p>
</div>
</head>
</html>";?>

【问题讨论】:

标签: php html mysql email


【解决方案1】:

改变这一行

<p><?php echo $link ?></p>

到这里

<p>$link</p>

您正在创建一个字符串,无需在字符串中放置 PHP 标记来回显变量。

【讨论】:

  • 谢谢,但有些代码不起作用,你也可以帮忙解决这个问题
  • 我看到的唯一错误是&lt;/html&gt;" 后面应该有一个;,就像这样&lt;/html&gt;";。除此之外,我们还需要特定的错误消息。
  • 出现错误消息:解析错误:语法错误,第 62 行的 email.php 中出现意外 $end
  • 那是因为你打开的else语句没有结束,把&lt;/html&gt;";?&gt;换成&lt;/html&gt;"; } ?&gt;
猜你喜欢
  • 2012-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-29
相关资源
最近更新 更多