Sent email using phpmailer but Outlook attachments count showing incorrect number

Viewed 147

I have implemented the mail functionality using PHP Mailer. Everything is working fine but it is giving wrong attachment count in outlook. I have tested using below code.

$mail = new SmtpNotification();
$mail->addAddress("test.email@gmail.com");
$mail->addAttachment($filepath. '/first.xlsx');
$mail->Subject = "Test Subject";
$mail->msgHTML('test Subject');
$mail->send();
echo "mail send";

Mail Sent successfully. But I got attachments count 2. enter image description here You can see that there is only 1 attachment but the count of attachments 2 and showing same file 2 times. When I print the object It is showing just 1 attachment.

[ReplyToQueue:protected] => Array
    (
    )
[attachment:protected] => Array
(
    [0] => Array
        (
            [0] => /var/www/html/project_name/file/first.xlsx
            [1] => first.xlsx
            [2] => first.xlsx
            [3] => base64
            [4] => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
            [5] => 
            [6] => attachment
            [7] => first.xlsx
        )

)
[CustomHeader:protected] => Array
(
)

I don't understand why this happening? Is it PHP Mailer issue or outlook issue? and How to solve it? Any help.

The SmtpNotification class is be like

require_once __DIR__ . '/../../../vendor/autoload.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
class SmtpNotification extends PHPMailer
{
    public function __construct($exceptions = null)
    {
       // Set config data
    }
    public function send()
    {
        if (!empty($this->to) && !empty($this->Body) && !empty($this->From)) {
            return parent::send();
        }
    }
}

I had also tried with basic functionality but getting the same.

require_once __DIR__ . '/../../vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Define all necessary constants here
$email = new PHPMailer();
$email->isSMTP();
$email->isHTML(false);
$email->Host = SMTP_HOST;
$email->Port = SMTP_PORT;
$email->SMTPSecure = SMTP_SECURE;
$email->SMTPDebug = SMTP_DEBUG;
$email->SMTPAuth = SMTP_AUTH;
$email->Username = MAIL_FROM_EMAIL;
$email->Password = MAIL_FROM_PASSWORD;
$email->From = MAIL_FROM_EMAIL;
$email->FromName = MAIL_FROM_NAME;
$email->CharSet = 'UTF-8';
$email->addAddress("mytest.email@email.com");
$email->addAttachment(Full_File_Path."/second.xlsx");
$email->Subject = "Test Subject";
$email->Body= 'test Body';
$email->send();
echo "mail send";

enter image description here

Still I am getting count 2. I don't understand why is this happening with me.

0 Answers
Related