I want to send an email with PHP script which include a gif image in it. It executed successfully(send mail with GIF Image) when I run it via browser URL, but when I run it via cron job/ schedule task it send only the mail body without GIF image. CODE :
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
require("connectionFile.php");
$mail = new PHPMailer(true);
try
{
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'xyz.domain.com';
$mail->SMTPAuth = true;
$mail->Username = 'xyz@domain.com';
$mail->Password = 'xyz';
$mail->Port = 25;
$mail->setFrom(xyz@domain.com, 'From:test server');
$mail->addAddress('abc@domain.com');
$mail->isHTML(true);
$mail->Subject = "TEST MAIL";
$mail->AddEmbeddedImage('test1.gif', 'logo_2u');
$mail->Body = "Dear user,<br/><br/><img src='cid:logo_2u' width='500px' height='750px'/></br></br>IT IS A TEST MAIL..<br/>";
$mail->send();
echo 'Message has been sent';
$mail->ClearAllRecipients();
}
catch (Exception $e)
{
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}
?>