0

I receive the a $BadgeImage URL from a form using $BadgeImage = $postData->get('BadgeImage', '', 'RAW');

And then I inserted the link or the variable on the body of the email. However after sending the email, the user will receive all the values from the form even the badge URL. Except when the URL is inside the tag the image is not displayed at all or it looks like the gmail strips-out the SRC attribute of tag.

My code:

        $body = "<div style='font-family:arial,helvetica,sans-serif;font-size:12px;'>
    <p>Hi ".$recipientName.",</p>

    **Badge image URL = $BadgeImage** <br/>
    <img src='".$BadgeImage."' width='150px' height='150px'/><br/>
    <img src='.$BadgeImage.' width='150px' height='150px'/><br/>
    <img src=".$BadgeImage." width='150px' height='150px'/><br/>
    <img src='$BadgeImage' width='150px' height='150px'/><br/>
    <img src=$BadgeImage width='150px' height='150px'/><br/>

    <hr style='border:0px;color:rgb(237,237,235);min-height:1px;width:525px;background-color:rgb(237,237,235)' />
    <div style='font-family:arial,helvetica,sans-serif;text-align:center;font-size:10px;color:rgb(102,102,102)'>
    <p>This email was sent to ".$badgeEarner." from the Community.</p>

    $senderEmail = $user->email;
    $senderName = $user->name;
    $sender = array($senderEmail, $senderName);

    $mail->ClearAddresses();
    $mail->setSender($sender);
    $mail->addRecipient($recipientEmail);
    $mail->Encoding = 'base64';
    $mail->setSubject(JText::_($badgeEarner.' Shared a Digital Badge'));
    $mail->IsHTML(true);
    $mail->setBody($body);

    $send = $mail->Send();

The GMAIL Results:

<div id=":4p9" class="ii gt m15116365f29ba2db adP adO"><div id=":4oz" class="a3s" style="overflow: hidden;"><div style="font-family:arial,helvetica,sans-serif;font-size:12px"><div class="adM">
    </div><p>Hi User,</p>
    <p>Andrew shared their badge,
    </p><p>Badge Info:</p>
    <p><strong>HISD Year 1 </strong><br><br>
    Badge image URL = <a href="https://www.viflearn.com/badges/images/HISD-developing-badge.png" target="_blank">https://www.viflearn.com/<wbr>badges/images/HISD-developing-<wbr>badge.png</a> <br>

    <img width="150px" height="150px"><br> <!-- src tag gets stripped!-->
    <img width="150px" height="150px"><br>
    <img width="150px" height="150px"><br>
    <img width="150px" height="150px"><br>
    <img width="150px" height="150px"><br>

    Badge description: Teacher completed 1st year of VIF Global Gateway program<br>
    Badge issued: 2015-07-28 19:39:43<br>
    Badge evidence: <a href="https://www.viflearn.com/index.php/component/k2/item/18804" target="_blank">https://www.viflearn.com/<wbr>index.php/component/k2/item/<wbr>18804</a><br>
    Badge criteria: </p>
    <p>You can view the badge at:</p>
    <p><a href="https://viflearn.com" target="_blank">VIF's Learning Center</a></p>
    <p>Have a nice day!</p><p></p></div>
    <hr style="border:0px;color:rgb(237,237,235);min-height:1px;width:525px;background-color:rgb(237,237,235)">
    <div style="font-family:arial,helvetica,sans-serif;text-align:center;font-size:10px;color:rgb(102,102,102)">
    <p>This email was sent to the Community.</p>
    <p>© 2016 .</p></div></div><div class="yj6qo"></div></div>
  • Could you please add var_dump($BadgeImage); exit; before sending the email and let us know what the results are? It should display a blank screen with the image URL – Lodder Nov 17 '15 at 16:31
  • You also don't appear to have closed the value of the $body variable. The last </p> tag, needs to be closed like so: </p>"; – Lodder Nov 17 '15 at 16:33
0

I found what was the problem. GMAIL is stripping the source attribute, so until you allow to display images then it gets embedded in the tag and finally you can see the image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.