I made a PHP script yesterday which send an email with a PDF as an attachment.
When I make a crontab with this script shedulded, I recieve the email but not the attachment. When I launch the script manually, I have the email and the attachment.
Here is the PHP code of the sendMail function :
function sendMail()
{
$corpse = file_get_contents(dirname(__FILE__).'/output/output.tpl');
$mail = new PHPMailer;
$mail->isMail();
$mail->IsHTML(true);
$mail->From='SenderMailAddress';
$mail->FromName='SenderName';
$mail->AddAddress('MyEmail');
$date = date("Ymd", time());
$yesterday = date("Ymd", strtotime("-1 day"));
if ($this->type == cur)
$pj = "/opt/birt/ReportEngine/output/bookingperiod_".$date.".pdf";
else
$pj = "/opt/birt/ReportEngine/output/bookingperiod_".$yesterday.".pdf";
echo $pj;
$mail->AddAttachment($pj);
$mail->AddReplyTo('NoReplyAddress');
$mail->Subject='SubjectOfTheMail';
$mail->Body=$corpse;
if (!$mail->Send())
echo "Error Sending: ".$mail->ErrorInfo;
unset($mail);
}
The script that I put as a crontask :
TODAY=`date "+%Y-%m-%d"`
export BIRT_HOME=/opt/birt
echo $TODAY
cd /opt/birt/ReportEngine
php GenPeriod.php PDF $TODAY /*first generation of a PDF file which will be the attachment for the PHP script*/
cd MY_PATH_TO_PHPSCRIPT_FOLDER
php Launche.php cur
Do someone already encounter the same type of problem ?
How can you solve it ?
Thanks ;)