1

I am trying to send an email to the user for password recovery. The code below allows me to send user information to user_Email. I was able to echo success but the issue here is that I am not receiving the mail from the mail.php. This mail is being setup in a hosting site called bluehost

<?php
    include("connection.php");
    require 'mail.php';
    if (isset($_POST['submit'])) {
        $user_Email = $_POST['email'];
        $select = $_POST['option'];
        $pin = $_POST['pin'];
        if (!empty($user_Email) && !empty($pin)) {  
            $reco = "SELECT * FROM tablename WHERE user_Email = '$user_Email' AND user_Pin = '$pin'";       
            $result = $MySQLi_CON->query($reco);
            foreach ($result as $key ) {
                $name = $key['user_Name'];
                $email = $key['user_Email'];
                $password =$key['user_Pass'];
                $pin = $key['pin'];
            }
            email($name, $email, $password, $pin);
        }
    }
?>

mail.php

<?php
    function email($name, $email, $password, $pin){     
        $to      = $email;
        $subject = "Password recovery";
        $message = "Hello";
        $headers = 'From:'. "\r\n" ."CC: someone@gmail.com";    
        $mail = mail($to,  $subject, $message,  $headers);
        if($mail){
            echo "success";
        }else{
            echo "fail";
        }
    }
?>
Synetrix
  • 59
  • 2
  • 12
  • Did you check the spams ? – JazZ Oct 08 '16 at 07:06
  • Use PHPMailer.. – Koen Hollander Oct 08 '16 at 07:08
  • yup, it is still not there – Synetrix Oct 08 '16 at 07:08
  • 1
    Go to this website and check your servers IP address or domain: https://www.spamhaus.org/lookup/ If it shows up on any list, that's most likely the reason why emails aren't getting through. – icecub Oct 08 '16 at 07:13
  • Did you try to send the mail from another host ? Test it with Gmail. Your code looks good. – JazZ Oct 08 '16 at 07:14
  • @AdrienLeber It's highly likely OP is using a private server at home or some free / cheap VPN. That's probably the reason since most mail services out there block everything except official mail servers. – icecub Oct 08 '16 at 07:15
  • even gmail doesn't work :( – Synetrix Oct 08 '16 at 07:16
  • 192.168.56.1 is not listed in the SBL 192.168.56.1 is not listed in the PBL 192.168.56.1 is not listed in the XBL – Synetrix Oct 08 '16 at 07:19
  • That's your lan ip address.. Go to http://whatismyipaddress.com/ to see your REAL ip address – icecub Oct 08 '16 at 07:20
  • it is listed in the pbl and cbl but not sbl. What does that mean – Synetrix Oct 08 '16 at 07:21
  • 1
    It means that you are running your server at home. Most email providers, like hotmail, gmail and that "bluehost" do not accept emails from private servers. They never will and no exception will ever be made. This is to prevent ppl from abusing email servers. – icecub Oct 08 '16 at 07:22
  • So, does that mean that I have to use a public server in order to use that feature? Or any other solution? – Synetrix Oct 08 '16 at 07:26
  • 2
    It means you have to use an official mailserver. You could for example create a gmail account and use the gmail smtp server to send the emails from. It means all the emails will come from that gmail address, but it will work. Another solution would be to hire an official mailserver. – icecub Oct 08 '16 at 07:28
  • If you want to know how to use the Gmail smtp server, have a look at the answer to this question: http://stackoverflow.com/questions/31736864/sending-emails-using-smtp-gmail-from-php You need the PHPMailer library for this: https://github.com/PHPMailer/PHPMailer – icecub Oct 08 '16 at 07:30
  • ok thanks a lot @icecub – Synetrix Oct 08 '16 at 07:36
  • No problem. Good luck and happy coding :) – icecub Oct 08 '16 at 07:37

0 Answers0