PHP邮件未使用此代码接收

时间:2016-09-26 07:02:42

标签: javascript php html

以下代码用于接收密码的电子邮件,但由于某些错误而未发送电子邮件。请查看代码并更正,更新发送电子邮件的新代码。我们在html中使用忘记密码,并使用php验证和发送电子邮件。

<?php
    if(isset($_POST['submit'])) { 
        mysql_connect('localhost','connect','connect') or die(mysql_error());
        mysql_select_db('connect') or die(mysql_error());
        $Email_Address = $_POST['Email_Address'];
        $q = mysql_query("SELECT * from erp_ng_form_reg WHERE    Email_Address='$Email_Address' ") or die(mysql_error());

        while($row = mysql_fetch_assoc($q)) {
            $result[] = $row;
        }
        //$p = mysql_affected_rows();
        //$res = mysql_fetch_array($q);
        $to = $result['Email_Address'];
        $message = $result['Password'];
        $subject="Remind password";
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        $headers .= 'From: <teamzulu@indoffgroup.com>' . "\r\n"; 
        $m=mail($to, $subject, $message, $headers);
        if($m) {
            echo'Check your inbox in mail';
            echo $message;
        } else {
            echo  "<script language='javascript' type='text/javascript'>
                   var abc  = document.getElementById('Email_Address').value;
                   alert(abc);</script>";
            echo 'mail is not send';
        }
    }
?>
<html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
        <style type="text/css">
            input {
                border:1px solid olive;
                border-radius:5px;
            }
            h1 {
                color:darkgreen;
                font-size:22px;
                text-align:center;
            }
        </style>
    </head>
    <body>
        <h1>Forgot Password<h1>
        <form action='#' method='post'>
            <table cellspacing='5' align='center'>
                <tr>
                    <td>Email Address:</td><td><input type='text' id='Email_Address' name='Email_Address'/></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type='submit' name='submit' value='Submit'/></td>
                </tr>
            </table>
        </form> 
    </body>
</html>  

1 个答案:

答案 0 :(得分:1)

<?php    
    if(isset($_POST['submit'])) { 
        mysql_connect('localhost','connect','connect') or die(mysql_error());
        mysql_select_db('connect') or die(mysql_error());
        $Email_Address = $_POST['Email_Address'];
        $q = mysql_query("SELECT * from erp_ng_form_reg WHERE    Email_Address='$Email_Address' ") or die(mysql_error());
        $numofemails = mysql_num_rows($q);
        if($numofemails > 0) {
            $result=mysql_fetch_assoc($q);
            $to = $result['Email_Address'];
            $message = $result['Password'];
            $subject="Remind password";
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
            $headers .= 'From: <teamzulu@indoffgroup.com>' . "\r\n"; 
            $m = mail($to, $subject, $message, $headers);
            if($m) {
                echo'Check your inbox in mail';
                echo $message;
            } else {
                echo  "<script language='javascript' type='text/javascript'>
                       var abc  = document.getElementById('Email_Address').value;
                       alert(abc);</script>";
                echo'mail is not send';
            }
        } else {
            echo 'Email Not found';
        }
    }
?>