-2

if you had solution please help me to fix it. please? mail was sent but it always visible on spam message. so how i keep it for inbox. please check my code deeply and give me right answer for matching my code. i used this point i create user login part and i want to give user to recovery option. then user will try to recovery i will send user to mail.

<?php
            session_start();
             mysql_connect(***, ****, ***);
              mysql_select_db('*****');
              $email = $_POST["email"]; 
              $_SESSION["email_id"]=$email;
              $a = rand(100,999999);
               //echo $a;
                $_SESSION["random"]=$a;
             $to = $email;
             $subject = "Verification Code";
             $message = 
                            "<!DOCTYPE html>
                            <html>
                                <head>
                                    <title></title>
                                </head>
                                <body>
                                    <h2 style='color:#000CA5;'>Your Verification code is : </h2><br><h2><b>$a</b></h2>
                                </body>
                            </html>";
             $header = "From:****@**.com \r\n";
             $header .= "MIME-Version: 1.0\r\n";
             $header .= "Content-type: text/html;charset=UTF-8" . "\r\n";
             $retval = mail ($to,$subject,$message,$header);
             if( $retval == true ) {
               // echo "Message sent successfully...";
                $sql = "update random set ran_num='$a' where emailid='$email'";
                mysql_query($sql);
                IF(!mysql_query($sql)){
                die("erroe processing :".mysql_error());
            }
            else{
                echo "<script language='javascript' type='text/javascript'> location.href='password_update.php' 
                </script>";
            }  
             }
          ?>

1 Answers1

0

You should look into updating your DNS records with an SPF record.

You can do this by adding the following as a TXT record. It will let email clients know the IP of your A record and the SPF records of your MX servers are allowed to send emails using that domain name.

v=spf1 a mx ~all

You can add a specific ip with ip4:xxx.xxx.xxx.xxx as well.

Ex: v=spf1 a mx ip4:127.0.0.1 ~all

If you need more complex rules or wish to read more into it, you should read through the SPF Record Syntax.

Almost every email client checks a domain's SPF record as part of it's spam check. Here's the description Google gives about the SPF Record and why having it is important:

We recommend that you create a Sender Policy Framework (SPF) record for your domain. An SPF record is a type of Domain Name Service (DNS) record that identifies which mail servers are permitted to send email on behalf of your domain.

The purpose of an SPF record is to prevent spammers from sending messages with forged From addresses at your domain. Recipients can refer to the SPF record to determine whether a message purporting to be from your domain comes from an authorized mail server.

For example, suppose that your domain example.com uses Gmail. You create an SPF record that identifies the G Suite mail servers as the authorized mail servers for your domain. When a recipient's mail server receives a message from user@example.com, it can check the SPF record for example.com to determine whether it is a valid message. If the message comes from a server other than the G Suite mail servers listed in the SPF record, the recipient's mail server can reject it as spam.

Charles
  • 1,121
  • 19
  • 30