2

This below code using for receive the email for password, but email not sent due to some error. Kindly review the code and corrected, update the new code for send email. We are using forgot password in html and validate and email using 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: <[email protected]>' . "\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>  
9
  • What is the error in this code ? Commented Sep 26, 2016 at 7:05
  • print_r($result) debug this ist, u will get the solution. Commented Sep 26, 2016 at 7:09
  • print_r($result) this is not in code. Commented Sep 26, 2016 at 7:22
  • LOL, print_r() is a function just for checking your $result, check what are you getting in $result... Commented Sep 26, 2016 at 7:26
  • before this line $to = $result['Email_Address']; use print_r($result); and share the result. Commented Sep 26, 2016 at 7:26

1 Answer 1

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: <[email protected]>' . "\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';
        }
    }
?>
Sign up to request clarification or add additional context in comments.

10 Comments

test this, may you not getting email id after query.
check your mail function is working on server or not? $msg = "First line of text\nSecond line of text"; mail("[email protected]","My subject",$msg); cehck by put the file on server with proper emailid.
all function configure to server. but mail not received.
try this one may authentication required! stackoverflow.com/a/23905054/1374160
yes. the mail function configure to server. but the mail not receiving till now.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.