I’m working with a PHP mail library to send emails that include file attachments. The problem I’m facing is that when I send emails to Gmail or Hotmail addresses, they always end up in the spam or junk folder instead of the inbox.
I’ve been trying to figure out what’s causing this issue. Is there something wrong with my email configuration? Are there specific settings I need to adjust to improve deliverability? I’m also wondering if using a different sending domain would help with this problem.
Here’s the code I’m currently using:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
require 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mailer = new PHPMailer();
$mailer->From = '[email protected]';
$mailer->FromName = 'John Doe';
$mailer->Subject = 'Document Attachment';
$mailer->Body = 'Hello there';
$mailer->AddAddress('[email protected]');
$mailer->AddAttachment('./document.pdf', 'document.pdf', 'base64', 'application/pdf');
$mailer->Send();
?>
What steps should I take to ensure my emails reach the inbox instead of spam?