HTML电子邮件中的php $链接

时间:2014-07-05 03:54:00

标签: php html mysql email

嘿,我已经开始制作一封用于密码重置和注册验证的HTML电子邮件。但是我做得很好。如果可能的话,有人请为我完成。我希望它从DB获取密码重置哈希和来自SESSION的用户名。我也很乐意提供更多代码。我不能用" JSFiddle"因为php代码需要工作。谢谢约书亚

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

1 个答案:

答案 0 :(得分:0)

更改此行

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

到这个

<p>$link</p>

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