Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts

    send HTML email with styling

    Hello,

    I am trying to send an HTML email with styling but however I apply styling nothing appears in the sent email. I have tried to use external stylesheets but that didnt work and also inline styling i.e

    Code:
    <p style='background-color: #000000;'>
    but this results in an email being sent but with no text in the body. Without any style the message comes through fine with unstyled text.

    How do you apply style to a PHP email? My code is below if you need to see it.

    Many thanks

    PHP Code:
    <?php

    if (isset($_POST['linkid'])) {

    $rows explode("%"$_POST['linkid']);
    $upperLimit $rows[16] + 17;
    //$to = $rows[2];

    $to "rtwpricetag@googlemail.com";
    $from "email test";


    $subject $name ' recommends rtwpricetag.com';
                    
    $headers 'Content-type: text/html; charset=iso-8859-1' "\r\n";
    $headers .= 'From: '$from "\r\n";
                    

    $message "<html>

    <body>


    <h1>" 
    $rows[0] . "'s Pricetag</h1>

    <h2>Grand Total:  " 
    $rows[$upperLimit+24] . "</h2>

    <table><tr><td>
    <p>Hi " 
    $rows[1] . "</p>
    <p>" 
    $rows[0] . " has sent you the following report of a round the world trip he/she calculated today on <a 

    href='http://www.rtwpricetag.com/round-the-world-trip-budget-cost-calculator.php'>rtwpricetag.com</a>. If you want to create one of your own and send it 

    back, please use the hyperlink above to do so.</p></td></tr></table>

    <br>

    <table>

    <tr><td><b>Leaving on:</b> " 
    date('jS F Y',$rows[3]) . "</td></tr>
    <tr><td><b>Returning on:</b> " 
    $rows[4] . "</td></tr>
    <tr><td><b>Length of trip:</b> " 
    $rows[5] . "</td></tr>
    </table>

    <br>

    <table>
    <tr><th colspan=2>Pre Costs</th></tr>
    <tr><td colspan=4></td></tr>
    <tr><td><b>Jabs</b></td><td>" 
    $rows[7] . "</td></tr>
    <tr><td><b>AirFares</b></td><td>" 
    $rows[8] . "</td></tr>
    <tr><td><b>Visas</b></td><td>" 
    $rows[9] . "</td></tr>
    <tr><td><b>Insurance</b></td><td>" 
    $rows[10] . "</td></tr>
    <tr><td><b>Tours</b></td><td>" 
    $rows[11] . "</td></tr>";


    $currency substr($rows[12], -3);
    $cost strrev(strstr(strrev($rows[13]), ' '));

    if (
    $cost ' ' $currency != '0.00 GBP')
    {
    $message $message "<tr><td>" $rows[12] . "</td><td>" $rows[13] . "</td></tr>";
    }

    $currency substr($rows[13], -3);
    $cost strrev(strstr(strrev($rows[15]), ' '));

    if (
    $cost ' ' $currency != '0.00 GBP')
    {
    $message $message "<tr><td><b>" $rows[14] . "</b></td><td><b>" $rows[15] . "</b></td></tr>";
    }


    $message $message "<tr><td colspan=4></td></tr><tr><th colspan=4>Destinations</th></tr><tr><td colspan=4></td></tr>";


    if (
    $rows[16] > 1)
    {

    $message $message "<tr><td><strong>Destination</strong></td><td><strong>Length Of Stay</strong></td><td><strong>Avg. Daily 

    Budget</strong></td><td><strong>Sub Total</strong></td></tr>"
    ;


    for (
    $x=17$x<intval($upperLimit); $x++)
    {

    $cells explode("|"$rows[intval($x)]);
    $message $message "<tr><td>" .$cells[0] . "</td><td>" $cells[2] . " Day(s)</td><td>" $cells[1] . "</td><td>" $cells[3] . "</tr>";

    }

    $gTotal explode("|"$rows[intval($upperLimit)]);

    $message $message "<tr><td colspan=3</td><td style='border-top: solid 1px; font-weight: bold;'>" $gTotal[0] . "</td></tr>";

    }
    else
    {
    $message $message "<tr><td colspan=4>no destinations added</td></tr>";
    }


    $message $message "<tr><td colspan=4></td></tr>
    <tr><th colspan=2>Lifestyle</th></tr>
    <tr><td colspan=4></td></tr>

    <tr><td><b>Accommodation</b></td><td>" 
    $rows[$upperLimit+1] . "</td></tr>
    <tr><td><b>Drinker</b></td><td>" 
    $rows[$upperLimit+2] . "</td></tr>
    <tr><td><b>Eater</b></td><td>" 
    $rows[$upperLimit+3] . "</td></tr>
    <tr><td><b>Shopper</b></td><td>" 
    $rows[$upperLimit+4] . "</td></tr>


    <tr><td colspan=4></td></tr>
    <tr><th colspan=2>Activities</th></tr>
    <tr><td colspan=4></td></tr>

    <tr><td><b>Zorbing</b></td><td>" 
    $rows[$upperLimit+5] . "</td></tr>
    <tr><td><b>Bungee Jumping</b></td><td>" 
    $rows[$upperLimit+6] . "</td></tr>
    <tr><td><b>Sky Diving</b></td><td>" 
    $rows[$upperLimit+7] . "</td></tr>
    <tr><td><b>Canoeing</b></td><td>" 
    $rows[$upperLimit+8] . "</td></tr>
    <tr><td><b>Rafting</b></td><td>" 
    $rows[$upperLimit+9] . "</td></tr>
    <tr><td><b>Cycling</b></td><td>" 
    $rows[$upperLimit+10] . "</td></tr>
    <tr><td><b>Whale Watching</b></td><td>" 
    $rows[$upperLimit+12] . "</td></tr>
    <tr><td><b>Canyoning</b></td><td>" 
    $rows[$upperLimit+13] . "</td></tr>
    <tr><td><b>Kayaking</b></td><td>" 
    $rows[$upperLimit+14] . "</td></tr>
    <tr><td><b>Surfing</b></td><td>" 
    $rows[$upperLimit+15] . "</td></tr>
    <tr><td><b>Rocking Climbing</b></td><td>" 
    $rows[$upperLimit+16] . "</td></tr>
    <tr><td><b>Scuba Diving</b></td><td>" 
    $rows[$upperLimit+17] . "</td></tr>
    <tr><td><b>" 
    $rows[$upperLimit+18] . "</b></td><td>" $rows[$upperLimit+19] . "</td></tr>
    <tr><td><b>" 
    $rows[$upperLimit+20] . "</b></td><td>" $rows[$upperLimit+21] . "</td></tr>
    <tr><td><b>" 
    $rows[$upperLimit+22] . "</b></td><td>" $rows[$upperLimit+23] . "</td></tr>
    <tr><td colspan=4></td></tr>
    <tr><th>GRAND TOTAL</th><td style='background-color: #D2433F; color: #FFFFFF; font-size: 18px;'>" 
    $rows[$upperLimit+24] . "</td></tr>
    </table>

    <a href='http://www.rtwpricetag.com/round-the-world-trip-budget-cost-calculator.php'>Create your own pricetag</a>


    </body>
    </html>"
    ;


    // Send
    mail($to$subject$message$headers);

    echo 
    $message;

    }

    ?>

  • #2
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts
    you need to MIME version, from what I was told. for example, the following example enables me to send a formatted email to someone:
    PHP Code:
    $send_header 'MIME-Version: 1.0' "\r\n" 
    'Content-type: text/html; charset=iso-8859-1' "\r\n" .
    'From: adam@domain.com' "\r\n" 'Reply-To: adam@domain.com';
    $send_body '
    <html>

    <head></head>

    etcc, etc...' 

    also be aware that tables are not reliable, because they come through differently with every mail server. they are even less reliable if you try to format them from left and right. in general, they will come through one on top of the other when you actually "see" the email on the recipient's end.
    Last edited by ajetrumpet; 01-22-2010 at 12:58 AM.

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    You should use something like PHPMailer to get this done. It will do it pretty easily and won't require all the messing around with large scripts
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #4
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts
    is PHP mailer a library of mailing functions? Do I download them and upload to my webserver?

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    http://phpmailer.worxware.com/
    It's a class. It's very easy to use
    check out the tutorial here
    http://phpmailer.worxware.com/index.php?pg=tutorial
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #6
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Hello,

    I am trying a simple example with phpmailer but nothing it coming through. Phpmailer is working fine because I have sent the same message fine with no styling. The majority is standard code, just the HTML table that is mine.

    PHP Code:
    <?php

    if (isset($_POST['linkid'])) {

    $rows explode("%"$_POST['linkid']);
    $upperLimit $rows[16] + 17;

    require_once(
    'PHPMailer/class.phpmailer.php');


    $message '<table>
    <tr><th colspan=2 style="font-family: Verdana, arial, sans; font-size: 18px; background-color: #333333; color: #FFFFFF;">Lifestyle</th></tr>
    <tr><td colspan=4></td></tr>

    <tr><td style="font-family: Verdana, arial, sans; font-size: 18px; background-color: #333333; color: #FFFFFF;">Accommodation</td></tr>
    <tr><td><b>Drinker</b></td></tr>
    <tr><td><b>Eater</b></td></tr>
    <tr><td><b>Shopper</b></td></tr>
    <tr><td colspan=4></td></tr>
    <tr><th colspan=2>Activities</th></tr>
    <tr><td colspan=4></td></tr>
    </table>

    <a href="http://www.rtwpricetag.com/round-the-world-trip-budget-cost-calculator.php">Create your own pricetag</a>'
    ;

    $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
    $mail->IsSendmail(); // telling the class to use SendMail transport

    try {
      
    $mail->AddAddress('rtwpricetag@googlemail.com''John Doe');
      
    $mail->SetFrom('name@yourdomain.com''First Last');
      
    $mail->Subject 'PHPMailer Test Subject via mail(), advanced';
      
    $mail->AltBody 'To view the message, please use an HTML compatible email viewer!'// optional - MsgHTML will create an alternate automatically
      
    $mail->MsgHTML($message);

      
    $mail->Send();
      echo 
    "Message Sent OK</p>\n";
    } catch (
    phpmailerException $e) {
      echo 
    $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
      echo 
    $e->getMessage(); //Boring error messages from anything else!
    }

    echo 
    $message;

    }
    ?>

  • #7
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts
    surely sending an HTML email should not be this hard. Is the error in the apostrophes or double quotes aroudn the HTML? I have tried many combinations of this.

    Even sending very basic messages works with a bit of styling but can then stop working if I add some more inline styling.

    I am viewing in gmail if that makes a difference. I can't even confidently style a table with a background color.

  • #8
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts
    gmail has nothing to do with it. i have used the mail function with plenty of incomming mail servers, and all of them support HTML formatting. i would go back to using the mail function out of simplicity. but that's just this humble man's opinion. it is really not that hard...

  • #9
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts
    php mailer is not complicated, its maybe the syntax around the styling that is wrong.

  • #10
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts
    the gmail client was bring all my styling and html through but it was not being displayed to me because i had to toggle a link to actually see it. For some reason i had to click on a "show quoted text" link (the only thing that would actually show) and then it all appeared. No idea why i had to do this but it cost me about 2 days of development.

  • #11
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Why are my emails hidden by - Show Quoted Text - ?

    I keep getting the same thing!!! Very annoying. I've even listened in on the
    socket level communications to see what is actually being sent to the SMTP server and there is NOTHING to indicate that the text is quoted,
    there are no tabs, no indentation or special characters.

    I'm getting this with PhpMailer 5.1. Did you ever find out why it happens?

    Mark

  • #12
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Found It!! It's a gmail "Feature"

    Why is it that after you spend 1/2 a day trying to find something and then
    desperately post a message to a forum, that you find the answer 10 seconds later? !!

    It turns out that there was nothing special about these message, and nothing wrong with them, and no "quoted text" in them.

    Instead, what is happening is that the Gmail email client is looking at a series of "test" messages that look very similar, and grouping them into a thread. It hides the "similar" parts of each message with is "- show quoted text-" link to
    make it easier to read a group of messages in a long thread, where everyone keeps quoting each other.

    I've been banging my head against the wall, sending test email messages and the whole problem was that I had sent too many similar messages -- oh the irony.


    http://constantcontact.custhelp.com/...quoted-text%22


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •