Solved

PHPMailer not showing HTML properly in gmail and outlook? why?

Posted on 2011-02-22
3
1,366 Views
Last Modified: 2012-05-11
Hi guys

I am send a HTML formatted email. but when i receive in gmail it doesnt show any html. not even the IMG.

when receiving in outlook it shows the IMG but doesnt process the styles.

when receiving on LIVE.com it shows as it should.

What am i doing wrong here.
function sendEmail($UserId,$content,$headLine="Message From DateFeast"){
    global $smtpServer;
    $select = "SELECT Email FROM Users WHERE UserId=$UserId LIMIT 1";
    $rs = mysql_query($select);
    $row = mysql_fetch_array($rs);
    $Email = $row['Email'];

    $str = "
        <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
        <html xmlns='http://www.w3.org/1999/xhtml'>
        <head>
        <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
        <style type='text/css'>
        *{font-family:Arial;font-size:8pt;}    
        body{background-color:#211c19;margin:0;}
        .mainTable{min-width:600px;border:1px solid black;}
        .top{text-align:left;float:left;width:auto;height:77px;border-bottom:3px solid #dfca91;background-color:#490105;vertical-align:top;font-size:8pt;padding-right:14px;overflow:hidden;}
        .middle{width:100%;	background-repeat:no-repeat;	background-position:0px -1px;background-color:#3c312d;vertical-align:top;}
        .middleContainer{padding-left:5px;padding-right:5px;	}
        .bottom{border-top:3px solid #dfca91;background-color:#490105;height:55px;}
        .ContainerDiv{vertical-align:top;}
        .ContainerDivHolder{z-index:1;position:relative;top:-44px;vertical-align:top;padding-left:16px;}
        .ContainerImage{position:relative;left:0px;z-index:2;}
        .ContainerGraphic{vertical-align:top;border:1px solid #84713e;overflow:hidden;}
        .ContainerTop{vertical-align:top;height:31px;width:100%;background-color:#3c0105;}
        .ContainerTopText{text-align:left;font-weight:bold;color:#fadf9a;padding-top:6px;padding-left:40px;}
        .ContainerContent{background-color:#c4af78;height:100%;}
        </style>
        </head>
        <body>
        <center>
        <table cellpadding='0' cellspacing='0' border='0' class='mainTable'>
	        <tr><td class='top'><div style='padding-left:20px;padding-top:5px;text-align:left;'><img src='http://www.mydomain.com/images/myimage.png'></div></td></tr>
            <tr><td class='middle'>
            <div style='padding:10px;'>
                <div class='ContainerGraphic' style='width:100%;'>
				    <div class='ContainerTop'><div class='ContainerTopText' style='padding-left:5px;'>".$headLine."</div></div>
				    <div class='ContainerContent' id='Div1' style='padding:5px;padding-top:10px;overflow:hidden;' >
                    ".$content."
                    <br><br>
                    </div>
                </div>
            </div>
            
            </td></tr>
            <tr><td class='bottom'>&nbsp;</td></tr>
        </table>
        </center>
        </body>
        </html>
    ";

    
    $mail = new PHPMailer();
    $mail->IsHTML(true); 
	$mail->From     = "noreply@mydomain.com";
	$mail->FromName = "MyDomain Email";
    $mail->Host     = $smtpServer;
    $mail->Mailer   = "smtp";
	$mail->Body    = $str;
	$mail->AltBody = $str;
	$mail->Subject = "MyDomain Email";
    $mail->AddAddress($Email, '');
    $mail->AddAddress('MyDomain@gmail.com', '');

    if(!$mail->Send()){
		$mail->ClearAddresses();
	    $mail->ClearAttachments();
        return false;
	}else{
		$mail->ClearAddresses();
	    $mail->ClearAttachments();
        return true;
    }
	die();

}

Open in new window

0
Comment
Question by:tim_carter
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 34954409
Because they don't support all of what you are doing.  Look here: http://www.campaignmonitor.com/css/  Gmail strips your 'style' sections and ignores them.  Outlook can be kind of crippled with HTML.  Email clients are not web browsers and those that use the web browser like Gmail, Yahoo, and Hotmail, rewrite your code to prevent their pages from breaking.
0
 
LVL 1

Author Comment

by:tim_carter
ID: 34954438
so is there a place where you can see the tags that are allowed?
0
 
LVL 1

Author Comment

by:tim_carter
ID: 34954446
sorry, checked the link. thankss
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CSS: Making responsive table look nicer 7 24
Cookie not unsetting 7 18
One field not displaying content (ASP Classic) 8 23
How do I fix this UPDATE error? 7 20
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question