tags:

views:

91

answers:

1

Hi guys, here is some code I've been working on, basically I need to set up a auto e-mail that gets sent to a user after they fill in a form, which at the moment it is doing, but the HTML is not displaying as it should inside of the email client.

I checked in Gmail, Outlook and Mac mail and none of them display the HTML correctly.

Here is the code

<?php
    session_start();
    $_SESSION['name'] = $_POST['name'];
    $name = $_SESSION['name'];
    $email_1 = $_POST['email_1'];
    $email_2 = $_POST['email_2'];
    $email_3 = $_POST['email_3'];
    $email_4 = $_POST['email_4'];
    $id_num = $_POST['id_num'];
    $tel = $_POST['tel'];
    $email = $_POST['email'];



    //sets the current date

    $curDate = date("Y-m-d");

    // Example


    require_once("mailclass/htmlMimeMail.php");
    $mail = new htmlMimeMail();
    $mail->setSubject("Your submission to MyWebsite!");
    $mail->setFrom("MyWebsite <[email protected]>");
    $mail->setFrom("MyWebsite <[email protected]>");
    $email_address = $email_1 . "," . $email_2 . "," . $email_3 ."," . $email_4 ;
    $mail->setBcc($email_address);





    $day = "
         <body style="'background: #000000; color: #FFFFFF;'">
         <div style="'background-image: url(http://www.website.com/images/mailerbg.jpg); width: 900px; height: 839px; margin: 0 auto;'">
         <div style="'width: 620px; height: 280px; position: relative; top: 155px; left: 25px;'">
                <h1><br>your friend $name<br><br><br></h1>
            </div>    
        </div>
        </body>";

    $mail->setHTML($day);   
            $result = $mail->send(array());

    ?> 

The code is pretty messy, from me screwing around with it so much, but basically none of the HTML shows up as it should in the email client once the message arrives at it's destination, how can I get it to display as a proper HTML page inside of the mail client?

I am assuming that my escaping is not done correctly, which is why nothing is showing as it should?

Thanx in advance!

+2  A: 

Showing the PHP code is useless in this case. We need to see a final, generated E-Mail.

What catches the eye, though, is some faulty quoting:

 <body style="'background: #000000; color: #FFFFFF;'">

should be

 <body style="background: #000000; color: #FFFFFF;">

Maybe that fixes it already.

In addition, according to this great guide, positioning is hardly supported in E-Mails - this could disturb the layout as well.

Pekka
Nice anwser but please keep in mind that you have to use single quotes for the decleration ( $day = '<!-- HTML_CODE -->'; ) when using pekka's code
Tim
@Tim Good eyes! I'm wondering how the OP's code is working at all, with all those nested double quotes?
Pekka
This is what jumped out at me, too. Just to add, if you want to escape those double quotes, just put a backslash before the quote, like so: `<body style=\"background: #000000; color: #FFFFFF;\">`That way, when you type the double quotes, you will not be closing your HTML body string prematurely. Alternatively, like Tim said, you can enclose the whole string in single quotes and use double quotes like normal, and vice-versa.
Ben Torell
It worked by adding the back slashes into the HTML code, like so <body style=\"background: #000000; color: #FFFFFF;\">, thanx for all the help guys!