Search code examples
phpiosiphonephpmailer

PHP generated e-mail > attachment missing at iPhone


I have encounterd an strange issue with one of my scripts. Using this code to send e-mail, the e-mails are send without any errors and are recieved with accessible attachments in normal Windows computers, iMac and android mobile devices.

But when the e-mail is received on an iPhone the mail shows paper clip but no attachment icons to open at all.

Any suggestions?

// attachment algemene voorwaarden
$check_upload = glob('../uploads/algemene_voorwaarden/*.*');
foreach($check_upload as $val) { $mail->AddAttachment($val); }

// other attachments
$check_upload = glob('../uploads/file_browser/bevestigingen/'.$mail_folder.'/*.*');
foreach($check_upload as $val) { $mail->AddAttachment($val); }

// convert \r\n to new lines
$mail_body = stripcslashes(isset($mail_body) ?  preg_replace('#(\\\r|\\\r\\\n|\\\n)#', '<br/>', $mail_body) : false);
$mail_body = str_replace("<br/><br/>","<br/>",$mail_body);

$mail->AddEmbeddedImage('../img/'.$config['logo_mail'], 'header');
$mail->AddEmbeddedImage('../img/mail_logo_torza.png', 'footer');

$mail->Subject = 'Orderbevestiging van '.$config['bedrijf'];
$mail->Body = '<html><head></head>'.
                    '<body style="margin: 10px;" style="font-family:Verdana, Verdana, Geneva, sans-serif; font-size:12px; color:#000000;">

                        <table bgcolor="'.$config['logo_color'].'" width="800" align="center" cellspacing="0" cellpadding="0">
                        <tr>
                            <td colspan="2"><img src="cid:header" width="800"></td>
                        </tr>
                        <tr style="padding: 3em;">
                            <td colspan="2">
                                '.$mail_body.'
                            </td>
                        </tr>
                        <tr valign="middle">
                            <td width="50%" align="right"><small><strong>Powered by &nbsp;&nbsp;</strong></small></td>
                            <td width="50%" align="left"><a href="http://www.torza.nl" target="_blank"><img src="cid:footer" width="50" alt="Torza"></a></td>
                        </tr>
                        </table>

                    </body></html>';

if(!$mail->Send()) { echo'<div class="alert alert-danger text-center" role="alert">Er is helaas iets fout gegaan.</div>'; die; }

Solution

  • The problem occured becauseof the way the imges were added in the header and footer.

    $mail->AddEmbeddedImage('../img/'.$config['logo_mail'], 'header');
    $mail->AddEmbeddedImage('../img/mail_logo_torza.png', 'footer');
    
    <img src="cid:header" width="800">
    
    <img src="cid:footer" width="50" alt="Torza">
    

    I have changed this now to

    <img src="data:image/jpg;base64,-- BASE 64 STRING -- " />
    

    The images were encoded here: https://www.motobit.com/util/base64-decoder-encoder.asp