向移动设备发送密码

时间:2014-03-23 08:23:31

标签: php

我使用以下代码向移动设备发送密码,代码似乎无法正常工作。 真的很感激任何帮助。

if (isset($_REQUEST['submit'])) {
    $phone = "select mobno from registration where username='" . $_GET['id'] . "' ";
    $mailto = "select regemail from registration where username='" . $_GET['id'] . "' ";
    $subject = "passcode";
    mail($mailto, $subject, $);
    echo '<script type="text/javascript">alert("Code Sent Successfully");</script>';
    echo '<meta http-equiv="refresh" content=",log.php">';
}

2 个答案:

答案 0 :(得分:0)

尝试编辑您的代码:

if (isset($_REQUEST['submit'])) {
    $phone = mysql_query("SELECT mobno FROM registration WHERE username='" . $_GET['id'] . "' ; ");
    $mailto = mysql_query("SELECT regemail FROM registration WHERE username='" . $_GET['id'] . "' ; ");
    $subject = "passcode";
    mail($mailto, $subject, $phone);
    echo '<script type="text/javascript">alert("Code Sent Successfully");</script>';
    echo '<meta http-equiv="refresh" content="0,log.php">';
}

不要忘记在开始时忘记连接到mySQL-Database!

答案 1 :(得分:0)

希望这有帮助。

/* DB connection */
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';

try {
    $dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
    die('Connection failed: ' . $e->getMessage());
}


if (isset($_REQUEST['submit'])) {
    $sql = 'SELECT mobno,regemail FROM registration WHERE username=:user'; // I suspect this should be id=:user due to $_GET['id'] and not $_GET['username']
    $sth = $dbh->prepare($sql);
    $sth->execute(array(':user' => $_GET['id']));
    $data = $sth->fetch(PDO::FETCH_ASSOC);

    $phone = $data['mobno'];
    $mailto = $data['regemail'];
    $subject = "passcode";

    mail($mailto, $subject, $phone);

    echo '<script type="text/javascript">alert("Code Sent Successfully");</script>';
    echo '<meta http-equiv="refresh" content=",log.php">';
}


您可以在PDO上找到有用的http://www.php.net/manual/en/class.pdo.php

上的php手册