0

When trigger my mail function , that mail goes to 'spam' folder not to 'inbox'. Can u please figure out whats the problem?

function send_user_email($mail, $to_email,$password, $first_name)
{
$html = "Hi $first_name, <br /><br />";
$html = $html . "<p> You have been registered with the system. Please find your login details below. </p>";
$html = $html . "User Name - $to_email <br />";
$html = $html . "Password - $password <br /> <br />";
$html = $html . "Regards, <br />";
$html = $html . "Team";

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtpout.XXX.XXX.XXX"; // sets GMAIL as the SMTP server
//  $mail->Host= "stmp.gmail.com"; // SMTP server
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Port = XXX; // set the SMTP port for the GMAIL server
$mail->Username  = "mailid"; // GMAIL username
$mail->Password  = 'password';// GMAIL password
$mail->From = "mailid";
$mail->FromName = "name";
$mail->Subject = "User invitation email";

$mail->AltBody = ""; // optional, comment out and test

$mail->IsHTML(true);
$mail->Body = nl2br($html);

$mail->AddAddress($to_email);

$mail->Send(); // send message
}
abdul
  • 57
  • 2
  • 12

2 Answers2

0

Few things which you can verify :)

  1. Have HTML and Text content.
  2. Try to add small but quality HTML body not just br's.
  3. Verify that the SMTP server which you use is set-upped properly. Usually if you use paid SMTP's this is not a problem, but if its your build it may have problems.
  4. SPF records are often, a problem as if they are missing any mail can/will be counted as spam.
Svetoslav
  • 4,686
  • 2
  • 28
  • 43
0

Normally, an email is marked spam if its "From:" header value's domain part does not match the domain that is actually sending the email.

The easiest way to bypass this is to use a "From:" that matches your domain, and use a "Reply-To:" header to the email that you set in "From:" header

For eg: if you are sending mail from mydomain.com and your from email is me@hotmail.com, you should change your headers to this:

From: me@mydomain.com

Reply-To: me@hotmail.com
Rajesh Kumar
  • 94
  • 1
  • 14