为什么我的php忘记密码而不发送电子邮件

时间:2014-01-22 11:45:24

标签: php email

查询明智的工作正常,我可以回显出与用户名相关联的电子邮件地址和密码,但是当它表明电子邮件正在发送时,我仍然没有在我的邮箱中收到它。知道出了什么问题吗?

这是我的完整代码:

<?php session_start();
mysql_connect("localhost","root","");//database connection
mysql_select_db("database");
if (isset($_POST['username'])){
    $username = $_POST['username'];
    $query="select * from dbusers where username='$username'";
    $result   = mysql_query($query);
    $count=mysql_num_rows($result);
    // If the count is equal to one, we will send message other wise display an error message.
    if($count==1)
    {
        $rows=mysql_fetch_array($result);
        $pass  =  $rows['password'];//FETCHING PASS
        echo "your pass is ::".($pass)."";
        $to = $rows['email'];
        echo "your email is ::".$to;
        //Details for sending E-mail
        $from = "Your Password details";
        $url = "http://localhost.com";
        $body  =  "Reset Password
        -----------------------------------------------
        Url : $url;
        email Details is : $to;
        Here is your password  : $pass;
        Sincerely,
        Coding Cyber";
        $from = "admin@support.com";
        $subject = "Here's your new password";
        $headers1 = "From: $from\n";
        $sentmail = mail ( $to, $subject, $body, $headers1 );
    } else {
    if ($_POST ['username'] != "") {
    echo "No such username found!</span>";
        }
        }
    //If the message is sent successfully, display sucess message otherwise display an error message.
    if($sentmail==1)
    {
        echo "<span style='color: #ff0000;'> Your Password Has Been Sent To Your Email Address.</span>";
    }
        else
        {
        if($_POST['username']!="")
        echo "<span style='color: #ff0000;'> Cannot send password to your e-mail address.Problem with sending mail...</span>";
    }
}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home: Webpage</title>
</head>
<body>
<form action="" method="post">
        <label> Enter your User ID : </label>
        <input id="username" type="text" name="username" />
        <input id="button" type="submit" name="button" value="Submit" />
    </form>
</body>
</html>

3 个答案:

答案 0 :(得分:1)

使用xampp时:在xampp-control中激活Mercury Mail Transport。 否则,您的本地邮件服务器无法启动,您无法发送邮件。

<?php
$a = 'your@email.com';
$b = ''; 
$msg = 'Hello';
$header = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($a, $b, $msg, $header);
?>

答案 1 :(得分:0)

如果您的文件位于localhost文件夹中,则需要安装本地邮件服务器,这不是很有用,但它可以正常工作。

如果您在网上(在主持人处)网站,它应该自动运行,或者转到cpanel并激活邮件。

答案 2 :(得分:0)

如果您在localhost中运行代码,那么这对您来说永远不会有用。如果您想从本地服务器发送邮件然后使用SMTP而不是PHP的简单邮件功能,那就更好了。