PHP邮件功能

时间:2015-06-27 07:34:35

标签: php email

我正在尝试建立一个人们可以上传笔记的网站,任何人都可以下载。对于任何人上传,都有注册和登录的规定。还有一个忘记密码链接,它执行以下操作: 1.询问用户emial id 2.检查它是否在数据库中 3.如果是,则发送带有更改密码链接的邮件到该邮件ID。 我尝试过使用灯泡服务器,并将其托管在2freehosting.com上。但是邮件没有被发送。消息错误正在屏幕上显示。代码在这里!任何有关这方面的帮助将不胜感激。 谢谢。

<!DOCTYPE html>
    <html>
    <head>
        <title>Forgot Password</title>
    </head>
    <body>
        <?php 
        error_reporting(0);
        $email=$_POST['email'];
        if($_POST['submit']=='Send')
        {
            /* Attempt MySQL server connection. Assuming you are running MySQL server */

            $link = mysqli_connect("localhost", "root", "", "demo");
            // Check connection
            if($link === false){
                die("ERROR: Could not connect. " . mysqli_connect_error());
            }
            $query="SELECT * from persons where email_address='$email'";
            $result=mysqli_query($link,$query) or die(error);
            if(mysqli_num_rows($result))
            {
                $message="You activation link is: http://link/for/changing/password.php?email=$email";
                mail($email, "Subject Goes Here", $message);
                $Message = "Email sent";
                header("Location:login.php?Message=".$Message);
                die;
             }
            else
            {
                echo "No user exist with this email id";
            }
        }
    ?>
    <form action="forgot.php" method="post">
        Enter you email ID: <input type="text" name="email">
        <input type="submit" name="submit" value="Send">
    </form>
   </body>

1 个答案:

答案 0 :(得分:1)

使用此代码,

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($email, "Subject Goes Here", $message, $headers);