vernes / YiiMailer

Yii extension for sending emails with layouts using PHPMailer
81 stars 38 forks source link

Php cli seems to ignore AddEmbeddedImage (no image attached) #10

Closed andyk72 closed 10 years ago

andyk72 commented 10 years ago

Hi, I am using the Yii 1.1.8 with YiiMailer 1.5.

I am sending html emails with images from views.

From inside a web app page in the browser, everything works great and I am successfully sending beautiful html email with attached images; images are perfectly embedded into the message body.

However, using the exact same piece of functionality (method) from php CLI (which I need for some system batch functionalities) the email is sent, but the images data for attachment (images raw data, related ids and src values modifications) are not included in the email body.

I also tried to force by myself the use of the AddEmbeddedImage method, but the results are the same.

What am I missing? Could you please help me?

I am attaching the email contents outputted by the php cli environment.

Thank you, Andrea


EMAIL CONTENT FROM PHP CLI


Date: Fri, 2 May 2014 16:33:57 +0200
Return-Path: <info@drivercomo.it>
To: andrea.padovani@gmail.com
From: "drivercomo.it" <info@drivercomo.it>
Subject: Iscriviti alla nostra applicazione Facebook!
Message-ID: <1bc37a8eaf3b7bbd9932c5d50f12fd17@localhost.localdomain>
X-Priority: 3
X-Mailer: PHPMailer 5.2.6 (https://github.com/PHPMailer/PHPMailer/)
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="b1_1bc37a8eaf3b7bbd9932c5d50f12fd17"
Content-Transfer-Encoding: 8bit

--b1_1bc37a8eaf3b7bbd9932c5d50f12fd17
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit              

                        VUOI SCOPRIRE LA TUA POSIZIONE GENERALE E RIVEDERE TUTTE LE CLASSIFICHE DEI TURNI CHE HAI CORSO?

                        CLICCA QUI!

                        e aggiungi sulla tua pagina FACEBOOK la nostra fantastica APP "DRIVER"!Con questa APP, utilizzabile da PC, scoprirai quanti turni hai corso, quanti podi hai conquistato, la tua posizione nel RANKING generale, quella dei tuoi amici e tanto altro!In più potrai invitare i tuoi amici ad una nuova sfida!

                        Dove Siamo:DRIVER Indoor ParkVia Pasquale Paoli 114Como, Co 22100Italy
             

--b1_1bc37a8eaf3b7bbd9932c5d50f12fd17
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<table cellspacing="0" cellpadding="10" style="color:#666;font:13px Arial;line-height:1.4em;width:100%;">
    <tbody>
        <tr>
            <td height="0">&nbsp;</td>
        </tr>
        <tr>
            <td>
                <!--
    $username
    $subscribeUrl
-->

<style>
    /* Shrink Wrap Layout Pattern CSS */
    @media only screen and (max-device-width: 599px) {
        td[class="hero"] img {
            width: 100%;
            height: auto !important;
        }
        td[class="pattern"] td {
            width: 100%;
        }
    }
</style>

<table cellpadding="0" cellspacing="0">
    <tr>
        <td class="pattern" width="760">
            <table cellpadding="0" cellspacing="0">
                <tr>
                    <td class="hero">
                        <img src="facebook-driver-app-header.jpg" alt="" style="display: block; border: 0;" />
                    </td>
                </tr>
                <tr><td height="20px">&nbsp;</td></tr>
                <tr>
                    <td align="left" style="font-family: arial,sans-serif; color: #333;">
                        <h2 style="line-height: 100%; font-size: 16px;">VUOI SCOPRIRE LA TUA POSIZIONE GENERALE E RIVEDERE TUTTE LE CLASSIFICHE DEI TURNI CHE HAI CORSO?</h2>
                    </td>
                </tr>
                <tr><td height="10px">&nbsp;</td></tr>              
                <tr>
                    <td align="left">
                        <!--<a href="http://apps.facebook.com/drivercomo/?cuid=161743169756"><img src="http://placehold.it/200x50/333&text=CLICCA QUI" alt="CLICCA QUI" style="display: block; border: 0;" /></a>-->
                        <a href="http://apps.facebook.com/drivercomo/?cuid=161743169756" style="display: block; width: 50%; height: 30px; text-align: center; line-height: 30px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; color: #fff!important; background: #56aded; text-align: center; text-decoration: none!important;">CLICCA QUI!</a>
                    </td>
                </tr>
                <tr><td height="10px">&nbsp;</td></tr>
                <tr>
                    <td align="left" style="font-family: arial,sans-serif; font-size: 14px; line-height: 20px !important; color: #666; padding-bottom: 20px;">
                        <p>e aggiungi sulla tua pagina FACEBOOK la nostra fantastica APP "DRIVER"!</p><p>Con questa APP, utilizzabile da PC, scoprirai quanti turni hai corso, quanti podi hai conquistato, la tua posizione nel RANKING generale, quella dei tuoi amici e tanto altro!</p><p>In più potrai invitare i tuoi amici ad una nuova sfida!</p>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <a href="http://drivercomo.it/"><img src="drivercomo-logo.jpg" alt="DRIVERCOMO.IT" style="display: block; border: 0;" /></a>
                    </td>
                    <p>&nbsp;</p>
                </tr>
                <tr>
                    <td align="left" style="font-family: arial,sans-serif; font-size: 14px; line-height: 20px !important; color: #666; padding-bottom: 20px;">
                        <p><strong>Dove Siamo:</strong>DRIVER Indoor Park<br />Via Pasquale Paoli 114<br />Como, Co 22100<br />Italy</p>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>            </td>
        </tr>
        <tr>
            <td height="0">&nbsp;</td>
        </tr>
    </tbody>
</table>
</body>
</html>

--b1_1bc37a8eaf3b7bbd9932c5d50f12fd17--
andyk72 commented 10 years ago

Update: solved!

PROBLEM

The problem was orginated by the fact that in yii console applications the 'webroot' alias does not point to the same directory as in web applications, but resolves to the same as the 'application' alias (e.g the 'protected' directory).

So, my images are in webroot.images.mail, as it is defined in

/protected/config/mail.php
...
'baseDirPath' => 'webroot.images.mail',
...

but they were searched for in application.images.mail and obviously were not found. Since this did not turned out in any explicit error, this was quite a bit tricky for me to understand:-)

SOLUTION

I solved the issue by adding at the top of

/protected/config/console.php

my custom definition of the webroot.images.mail alias:

Yii::setPathOfAlias('webroot.images.mail', 'C:\\my_web_app_root\\images\\mail');
vernes commented 10 years ago

That is a great find, sorry about your problem. There is an issue with Yii https://github.com/yiisoft/yii/issues/1267

Basically you should not rely on webroot alias but define your own. Maybe I'll add a note about this in documentation.