0

I am searching on the web how to fix the problem with phpmailer going to the spam-box inside outlook(Hotmail).

I tried a lot of things but none of them worked.

$result = $statement->fetchAll();
    if(isset($result))
    {
        $base_url = "http://www.gester.nl/loginsystem2/";  //change this baseurl value as per your file path
        $mail_body = "
        <p>Hi ".$_POST['user_name'].",</p>
        <p>Thanks for Registration. Your password is ".$user_password.", This password will work only after your email verification.</p>
        <p>Please Open this link to verified your email address - <a href='".$base_url."email_verification.php?activation_code=".$user_activation_code."'>".$base_url."email_verification.php?activation_code=".$user_activation_code."</a>
        <p>Best Regards,<br />Gester</p>
        ";
        require 'class/class.phpmailer.php';
        $mail = new PHPMailer;
        $mail->IsSMTP();                                //Sets Mailer to send message using SMTP
        $mail->Host = 'xxxx';       //Sets the SMTP hosts of your Email hosting, this for Godaddy
        $mail->Port = '587';                                //Sets the default SMTP server port
        $mail->SMTPAuth = true;                         //Sets SMTP authentication. Utilizes the Username and Password variables
        $mail->Username = 'xxxx';                   //Sets SMTP username
        $mail->Password = 'xxxx';                   //Sets SMTP password
        $mail->SMTPSecure = 'tls';                          //Sets connection prefix. Options are "", "ssl" or "tls"
        $mail->From = 'xxxx@mail.com';          //Sets the From email address for the message
        $mail->FromName = 'Gester';                 //Sets the From name of the message
        $mail->Sender = $_POST['user_email'];
        $mail->AddAddress($_POST['user_email'], $_POST['user_name']);       //Adds a "To" address
        $mail->WordWrap = 50;                           //Sets word wrapping on the body of the message to a given number of characters
        $mail->IsHTML(true);                            //Sets message type to HTML
        $mail->Subject = 'Email Verification';          //Sets the Subject of the message
        $mail->Body = $mail_body;                           //An HTML or plain text message body
        if($mail->Send())                               //Send an Email. Return true on success or false on error
        {
            $message = '<label class="text-success">Register Done, Please check your mail.</label>';
        }
        else {
            $message = '<label class="text-danger">Mail could not be send.</label>';
        }
    }

I hope someone could give me a good explanation on how to fix this exactly. Because there are many answers online but they are not accurate.

Ghanshyam Nakiya
  • 1,602
  • 17
  • 24

1 Answers1

1

First of all I can see that you are using a very old version of PHPMailer that contains many bugs and several known vulnerabilities, so upgrade now.

In answer to your question, don't do this:

$mail->Sender = $_POST['user_email'];

That's forgery and will either cause your messages to be rejected altogether or spam filtered. Use your regular from address instead, i.e., don't bother setting the Sender property at all.

Even with this fixed, there is no guarantee that your messages will not be marked as spam; this is not something you have any direct control over, and it will vary from one ISP to another. There are many other factors that can influence this such as SPF, DKIM, DMARC, TLS, DNS settings, your content and sending history, and many other things.

While I'm here, when you say Your password is ".$user_password, this suggests that you might be storing passwords in plain text. Don't do that, it's very insecure, and PHP has built-in functions to help you do it the right way, and there are plenty of answers on here and elsewhere to help you with that.

Synchro
  • 35,538
  • 15
  • 81
  • 104
  • 1
    Finally a clear solution, i thank you man, really. When i saw the email going into the normal inbox i was so happy. Thank you for your advice. Have a nice day! –  Jun 12 '19 at 13:54
  • 1
    For people searching for the same as i was searching for. I followed what Synchro said. I updated my phpmailer and followed the rest what he is saying above! –  Jun 12 '19 at 13:55
  • And by the way with the $user_password, i let the user_password variable go through this : ```` $user_password = rand(100000,999999); $user_encrypted_password = password_hash($user_password, PASSWORD_DEFAULT); ```` That is safe right? –  Jun 12 '19 at 17:59