HTML Formatted Emails

thread: 9 messages  |  last: a year ago  |  started: wednesday, march 10, 2010, 8:40 am pst


#1  |  stromee (Minneapolis, MN) United States of America
Wednesday, March 10, 2010, 8:40 AM PST

Hello,

For some reason when I send HTML formatted emails via Qcodo's QEmailMessage and QEmailServer, I can't see any images.  However, when I send manually via PHP mail function.  It works just fine.  Do I need to set any additional headers or anything before sending?  Here's my code:

<?php
    
include('app/includes/prepend.inc.php');
    
// We want to define our email SMTP server (it defaults to "localhost")
    // This would typically be done in prepend.inc, and its value should probably be a constant
    // that is defined in _configuration.inc
    //QEmailServer::$SmtpServer = 'mx.acme.com';

    // Create a new message
    // Note that you can list multiple addresses and that Qcodo supports Bcc and Cc
    
$objMessage = new QEmailMessage();
    
$objMessage->From 'ACME Reporting Service <reporting@acme.com>';
    
$objMessage->To 'Mr. Tester <myemail@gmail.com>';
    
//$objMessage->Bcc = 'audit-system@acme.com';
    
$objMessage->Subject 'Report for ' QDateTime::NowToString(QDateTime::FormatDisplayDate);

    
// Setup Plaintext Message
    
$strBody "Dear John and Jane Doe,\r\n\r\n";
    
$strBody .= "You have new reports to review.  Please go to the ACME Portal at http://portal.acme.com/ to review.\r\n\r\n";
    
$strBody .= "Regards,\r\nACME Reporting Service";
    
$objMessage->Body $strBody;

    
// Also setup HTML message (optional)
    
$strBody 'Dear John and Jane Doe,<br/><br/>';
    
$strBody .= '<img height=131 src="http://www.p1computerparts.com/images/email_order_banner.jpg" width=529 />';    
    
$strBody .= '<b>You have new reports to review.</b>  Please go to the <a href="http://portal.acme.com/">ACME Portal</a> to review.<br/><br/>';
    
$strBody .= 'Regards,<br/><b>ACME Reporting Service</b><br />';
    
$objMessage->HtmlBody $strBody;

    
// Add random/custom email headers
    
$objMessage->SetHeader('x-application''ACME Reporting Service v1.2a');

    
// Send the Message (Commented out for obvious reasons)
    
QEmailServer::Send($objMessage);
    
    
// THIS WORKS
    //$headers  = 'MIME-Version: 1.0' . "\r\n";
    //$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    //mail('myemail@gmail.com', 'Hello', $strBody, $headers);


    // Note that you can also shortcut the Send command to one line for simple messages (similar to PHP's mail())
    
$strBody "Dear John and Jane Doe,\r\n\r\n";
    
$strBody .= "You have new reports to review.  Please go to the ACME Portal at http://portal.acme.com/ to review.\r\n\r\n";
    
$strBody .= "Regards,\r\nACME Reporting Service";
//    QEmailServer::Send(new QEmailMessage('reporting@acme.com', 'jdoe@acme.com', 'Alerts Received!', $strBody));
?>
bc.
#2  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Wednesday, March 10, 2010, 9:45 PM PST

what do you mean by “can't see”?  Which email client are you using to view the email?

Have you “view sourced” the email in your client to see if it is properly formatted HTML?

Lastly, remember that some email clients block image downloads from remote servers on email reads... have you ensured that this isn't the cause of the issue?

#3  |  stromee (Minneapolis, MN) United States of America
Thursday, March 11, 2010, 8:33 AM PST

Mike,

I receive the email with the <img /> code (I did view the source), but I literally can't see the image in my email client (using Gmail and Mac Mail).  When I send the same exact email (as shown in the example) via the PHP mail function and manually set my HTML headers, I'm able to see the image just fine in the same email client.

Are you able to send HTML formatted emails with Qcodo without an issue?  Something seems to be wrong with the headers or something.  For now, I'll just have to go with the PHP mail function.

Thanks for any help,
Chris

#4  |  Zbyszek Czarnecki (Warsaw, PL) Poland
Wednesday, March 17, 2010, 5:18 AM PDT

QEmailServer sends malformed html messages (no QuotedPrintable encoding ), and perhaps thats might help.

bugfixed QEmailServer:
http://github.com/klucznik/qcodo

#5  |  Nelson Graziani (Rosario, Santa Fe) Argentina
Monday, July 12, 2010, 6:22 PM PDT

Hello to everybody, this is my first post.

Zbyszek, your code really works ! It solves the problem.
The only thing I have noticed is that it uses a static method in QString.class.php that is only available in Qcodo 0.4.15 or above (which is currently a development version).
I copied and pasted the method in QString.class.php in my version of Qcodo and worked like a charm.

Thanks for posting the solution!  

PS: I'm using qcodo 0.4.10

#6  |  Nelson Graziani (Rosario, Santa Fe) Argentina
Monday, July 12, 2010, 7:28 PM PDT

I'll try to be clearer.
I'm using qcodo 0.4.10 and I was having trouble with html emails.
I replaced QEmailServer.class.php (located in includes/qcodo/_core/framework) with the code that posted our friend from Poland.
I tried to send an email and I got a php error (not from the framework) saying that the app was calling and unknown static method in QString.class.php. The method was called IsLengthBeetween().
I searched qcodo API for that method and it said it was available in qcodo 0.4.15 or greater, so I downloaded qcodo 0.4.16 and copied from this version's QString.class.php methods IsLengthBeetween and ConvertToCamelCase. Then pasted the two methods' code to QString.class.php in the qcodo version I was using and voila !!

I hope it doesn't affect other functionality of the framework... it doesn't seem so so far.

#7  |  Zbyszek Czarnecki (Warsaw, PL) Poland
Tuesday, July 13, 2010, 2:40 AM PDT

My changes were incorporated into qcodo now since 0.4.15 so no need for copy and paste just update your qcodo.

And don't worry about affecting other bits, I think that is not possible in this case.

#8  |  Nelson Graziani (Rosario, Santa Fe) Argentina
Wednesday, July 14, 2010, 12:49 PM PDT

Zbyszek, where can I get version 0.4.15 ? It the site it says that the current stable version is 0.4.14.

#9  |  Zbyszek Czarnecki (Warsaw, PL) Poland
Wednesday, July 14, 2010, 2:23 PM PDT

It's a developer release, should be stable as 0.4.15 and 0.4.16 were bugfix releases mostly.

http://www.qcodo.com/downloads/



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.