0

I'm trying to send emails using phpmailer but every mail that i sended, finish in the spam folder.

This is the code

require("phpmailer/class.phpmailer.php"); // or wherever you put phpmail.class

$username="xxx";
$password="yyy";

$mail = new PHPMailer;
$mail->isMail();
$mail->IsHTML(true);
$mail->SMTPDebug = 4;
$mail->setFrom('news@lexvirtual.cl', 'Lexvirtual');
$mail->addAddress("roasdf@gmail.com", "hola");
$mail->Subject = 'Nueva postulación lexvirtual.cl';
$mail->AddEmbeddedImage('../assets/img/common/lexvirtual_logo.png', 'logoimg', '../assets/img/common/lexvirtual_logo.png');

$body = file_get_contents('email_templates/register.php'); 
$body = str_replace('%username%', $username, $body);
$body = str_replace('%password%', $password, $body);
$message = $body;
$mail->msgHTML($message);

if ($mail->send()) {
echo "email enviado";
} else {
echo "email no enviado";
}

I'm sending the email from my domain that is lexvirtual (the same domain that i'm using to send the email (news@lexvirtual.cl)).

Now i'm using a template using html but when i send a email using only text, still send the email to spam. I tried reading other questions about this problem,but still can't fix the issue.

Someone can help me please?

1 Answers1

0

To configure your server for all anti-spam mechanisms is very difficult and you have to be sure that your SPF record is correct, that your reverse dns configuration is correct and DMARC is also not a wrong decision.

So in most cases if you don't want to configure all that things it's better to send your mails over SMTP to a bigger mail provider and let them send your Email out.

Phpmailer con send your mails over SMTP to another provider something like this:

$phpmailer->IsSMTP(); 
$phpmailer->SMTPAuth = true; 
$phpmailer->Host     = "smtprelaypool.ispgateway.de"; 
$phpmailer->Username = 'mymail@example.com'; 
$phpmailer->Password = 'MyPassword'; 
$phpmailer->Port = 25;  
René Höhle
  • 26,716
  • 22
  • 73
  • 82