Thursday, October 29, 2026
HomeiOS Developmentphp - Clean e mail (Apple Mail) with Content material-type: multipart

php – Clean e mail (Apple Mail) with Content material-type: multipart

[ad_1]

I’ve made an ‘utility’ in PHP that manages friends signing out and in by way of a kiosk. If there’s a fireplace, a register is generated for printing. Within the occasion that printing the register just isn’t attainable an e mail can also be despatched to key workers.

The e-mail incorporates every friends title and a picture. The picture is saved as a Base64 encoded string, I’ve constructed the e-mail utilizing the header Content material-type:multipart/various;boundary=#### and this appeared to work effectively, till workers which have iPhones identified they obtain an e mail with simply the final picture and nothing else! I’ve tried utilizing different multipart headers – multipart/blended leads to a clean e mail with all of the photographs as attachments (that can not be downloaded). The e-mail shows effective in browser and on Android telephones.

Under is an instance of the e-mail code I’m producing. Have I used the boundaries incorrectly? I had beforehand positioned the pictures beneath the HTML content material however I had learn on SO that this will trigger points. It made no distinction to Android/Internet or Apple that I can inform.

MIME-Model: 1.0
Content material-type: multipart/various;boundary=3878aa63ed6083829fa5c76c888bf5aa
From: <no-reply@***.web>
Return-Path: no-reply@***.web
Message-ID: <***@***.***.native>
X-OriginalArrivalTime: 23 Feb 2022 09:51:49.0558 (UTC) FILETIME=[FA398D60:01D8289A]

--3878aa63ed6083829fa5c76c888bf5aa
Content material-Kind: picture/jpg; title="Robin0.jpg"
Content material-Switch-Encoding: base64
Content material-ID: <Robin0>
Content material-Disposition: inline; filename="Robin0.jpg"


--3878aa63ed6083829fa5c76c888bf5aa
Content material-Kind: textual content/html; charset="utf-8"
Content material-Switch-Encoding: 8bit
Content material-type: textual content/html;charset=UTF-8

<!DOCTYPE html>
        <html>
            <head>
                <meta charset="utf-8">
                <title>Customer Register 22/02/2022</title>
            </head>
        <physique>
            <div type="background:#EFEFEF;">
                <div type="peak:57px;background: #0C2D4E;">
                    <div type="width:720px; margin:0 auto;place:relative;">
                        <img src="https://***.web/brand.png" type="padding:5px 10px 5px 10px;">
                    </div>
                </div>
            <div type="background:white; margin:0 auto; width:720px;padding:10px;"><middle><h1>Guests on 22/02/2022</h1></middle><desk class="visitorTable" border="1" width="100%">
        <thead>
            <tr type="background:#0C2D4E;text-align:middle;shade:white;font-weight:800;">
                <td type="width:102px;"></td>
                <td>Title</td>
                <td>Firm</td>
                <td>Car</td>
                <td>Visiting</td>
                <td type="width:75px;">Time In</td>
                <td type="width:75px;">Time Out</td>
                <td type="width:70px;"><span class="printonly">Current?</span></td>
            </tr>
        </thead><tr class="" type="background:#bcffd0; ">
                        <td type="peak:65px; padding:0;"><div type="peak:100px; overflow:hidden;"><img class="visitorImage" type="peak:100px;width:100px;" src="cid:Robin0" /></div></td>
                        <td type="padding:3px;">Robin</td>
                        <td type="padding:3px;">Some Firm</td>
                        <td type="padding:3px;">AB22 ABC</td>
                        <td type="padding:3px;">Someperson</td>
                        <td type="text-align:middle">22/02/2022 15:08:26</td>
                        <td type="text-align:middle"></td>
                        <td type="text-align:middle"></td>
                    </tr></desk></div>
                <div type="background:#4A4A49;shade:white;padding:0px; margin:0px;">
                    <div type="width: 720px;margin:0 auto;place:relative; padding:3px;">
                    <small>Please don't reply to this e mail. When you have any points, please contact the us by way of e mail <a mode="shade:white;" href="mailto:***@***.web">***@***.web</a>.</small>
                    </div>
                </div>
            </div>
        </physique>
        </html>
--3878aa63ed6083829fa5c76c888bf5aa--

I don’t imagine the code producing the e-mail pertains to this situation, (indirectly anyway) however right here is an instance (considerably sanitized):

$boundary=md5(uniqid(rand()));
whereas ($row = mysqli_fetch_array($question)) {

    if (isset($row['dateTimeOut'])) {
        $dateTimeOut = date("d/m/YrnH:i:s", strtotime($row['dateTimeOut']));
        $color="#ffc0bc";
        $class="screenonly";
        $emailStyle="show:none;";
    } else {
        $class="";
        $emailStyle="";
        $dateTimeOut="";
        $color="#bcffd0";
    }

    if (isset($row['dateTimeOut'])) {
        $dateTimeOut = date("d/m/YrnH:i:s", strtotime($row['dateTimeOut']));
        $color="#ffc0bc";
    } else {
        $dateTimeOut="";
    }

    if (empty($emailStyle)) { //Solely add the row if the person is presently signed in!
        $imageName = str_replace(' ', '', $row['Name']) . $i; //Solely create the file title as soon as, it's used repeatedly

        $imageRow .= "--" . $boundary . "rn";
        $imageRow .= 'Content material-Kind: picture/jpg; title="' . $imageName . '.jpg"' . "rn";
        $imageRow .= 'Content material-Switch-Encoding: base64' . "rn";
        $imageRow .= 'Content material-ID: <' . $imageName . '>' . "rn";
        $imageRow .= 'Content material-Disposition: inline; filename="' . $imageName . '.jpg"' . "rn";
        //$imageRow .= 'Content material-Location: '.$row['Name'].'.jpg' . "n";
        $imageRow .= $row['Image'] . "rn";

        $registerRow .= "<tr class="$class" type="background:" . $color . "; ' . $emailStyle . "'>
                    <td type="peak:65px; padding:0;"><div type="peak:100px; overflow:hidden;"><img class="visitorImage" type="peak:100px;width:100px;" src="https://stackoverflow.com/questions/71235847/cid:" . $imageName . "" /></div></td>
                    <td type="padding:3px;">" . $row['Name'] . "</td>
                    <td type="padding:3px;">" . $row['Company'] . "</td>
                    <td type="padding:3px;">" . $row['Registration'] . "</td>
                    <td type="padding:3px;">" . $row['Visiting'] . "</td>
                    <td type="text-align:middle">" . date("d/m/YrnH:i:s", strtotime($row['dateTimeIn'])) . "</td>
                    <td type="text-align:middle">" . $dateTimeOut . "</td>
                    <td type="text-align:middle"></td>
                </tr>";
        $i++;
    }
}

$to = 'robin@***.web';
$topic="Customer register for " . date("d/m/Y", strtotime($_POST['date']));

$mailHeader = "<!DOCTYPE html>
        <html>
            <head>
                <meta charset="utf-8">
                <title>Customer Register " . date("d/m/Y", strtotime($_POST['date'])) . "</title>
            </head>
        <physique>
            <div type="background:#EFEFEF;">
                <div type="peak:57px;background: #0C2D4E;">
                    <div type="width:720px; margin:0 auto;place:relative;">
                        <img src="https://***.web/brand.png" type="padding:5px 10px 5px 10px;">
                    </div>
                </div>
            <div type="background:white; margin:0 auto; width:720px;padding:10px;">";

$mailFooter = "</div>
                <div type="background:#4A4A49;shade:white;padding:0px; margin:0px;">
                    <div type="width: 720px;margin:0 auto;place:relative; padding:3px;">
                    <small>Please don't reply to this e mail. When you have any points, please contact us by way of e mail <a mode="shade:white;" href="mailto:***@***.web">***@***..web</a></small>
                    </div>
                </div>
            </div>
        </physique>
        </html>";

$desk="<desk>";
$desk = "<desk class="visitorTable" border="1" width="100%">
        <thead>
            <tr type="background:#0C2D4E;text-align:middle;shade:white;font-weight:800;">
                <td type="width:102px;"></td>
                <td>Title</td>
                <td>Firm</td>
                <td>Car</td>
                <td>Visiting</td>
                <td type="width:75px;">Time In</td>
                <td type="width:75px;">Time Out</td>
                <td type="width:70px;"><span class="printonly">Current?</span></td>
            </tr>
        </thead>";
$desk .= $registerRow;
$desk .= '</desk>';

$headers = "MIME-Model: 1.0" . "rn";
$headers .= 'Content material-type:multipart/various;boundary='. $boundary . " rn";
$headers .= 'From: <no-reply@***.web>' . "rn";

$topBoundary = 'This message requires HTML/Wealthy content material to show.' . "rn";
$topBoundary .= "--" . $boundary . "rn";
$topBoundary .= 'Content material-Kind: textual content/html; charset="utf-8"' . "rn";
$topBoundary .= 'Content material-Switch-Encoding: 8bit' . "rn";

$message = $imageRow . $topBoundary . 'Content material-type:textual content/html;charset=UTF-8' . "rn" . $mailHeader . "<middle><h1>Guests on " . date("d/m/Y", strtotime($_POST['date'])) . "</h1></middle>" . $desk . $mailFooter . "rn--" . $boundary . '--';

mail($to, $topic, $message, $headers);

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments