css not working in email sending using AWS












2















I am developing a website in php and want to send email to a user when user signs up.



I am able to do it successfully.
Even i using html format and it's sending in html format.



I tried this. I know images should be uploaded to server but i will do it later.



$bodyPart = '
<body style="background-color:#FFFFFF;">

<img id="header" style="position:absolute; left:85px; top:50px; " src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>


<img id="cloths" style="position:absolute; left:275px; top:25px;" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>

<font size="7" style="font-family:Times new Roman; position:absolute; left:50px; top:120px;">Thank YOU</font>

<font size="3" style="font-family:Times new Roman;position:absolute;left:50px; top:165px;">For registering with our team </font>

<img id="bag" style ="position:absolute; left:290px; top:345px;"src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>

<img style="position:absolute; left:30px; top:440px; "id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>

</body>

';

$m->setMessageFromString($plainTextBody,$bodyPart);

print_r($ses->sendEmail($m));


I should be getting this output



enter image description here



But i am getting this instead.



enter image description here



But the problem is formatting is not properly done even if it works in my localhost as a independent file. I tried to use External CSS, Internal CSS and inline CSS. But it's not working.



Any example of CSS working with html in sending email would be very helpful.



Thanks In advance.










share|improve this question

























  • see updated question.

    – keen
    Sep 23 '13 at 6:15











  • we don't know what setMessageFromString() and sendEmail() doing...

    – Rajeev Ranjan
    Sep 23 '13 at 6:18











  • setMessageFromString is used to set email body part, where sendEmail is used to send an email after setting up message,sendTo,from and subject part.

    – keen
    Sep 23 '13 at 6:30











  • your css is working and if you are expecting your images use the full path of image in src of image.

    – Rajeev Ranjan
    Sep 23 '13 at 6:39











  • i know that i need to specify full path of image, as i already said in my question. How can you say that my css is working?

    – keen
    Sep 23 '13 at 6:44
















2















I am developing a website in php and want to send email to a user when user signs up.



I am able to do it successfully.
Even i using html format and it's sending in html format.



I tried this. I know images should be uploaded to server but i will do it later.



$bodyPart = '
<body style="background-color:#FFFFFF;">

<img id="header" style="position:absolute; left:85px; top:50px; " src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>


<img id="cloths" style="position:absolute; left:275px; top:25px;" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>

<font size="7" style="font-family:Times new Roman; position:absolute; left:50px; top:120px;">Thank YOU</font>

<font size="3" style="font-family:Times new Roman;position:absolute;left:50px; top:165px;">For registering with our team </font>

<img id="bag" style ="position:absolute; left:290px; top:345px;"src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>

<img style="position:absolute; left:30px; top:440px; "id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>

</body>

';

$m->setMessageFromString($plainTextBody,$bodyPart);

print_r($ses->sendEmail($m));


I should be getting this output



enter image description here



But i am getting this instead.



enter image description here



But the problem is formatting is not properly done even if it works in my localhost as a independent file. I tried to use External CSS, Internal CSS and inline CSS. But it's not working.



Any example of CSS working with html in sending email would be very helpful.



Thanks In advance.










share|improve this question

























  • see updated question.

    – keen
    Sep 23 '13 at 6:15











  • we don't know what setMessageFromString() and sendEmail() doing...

    – Rajeev Ranjan
    Sep 23 '13 at 6:18











  • setMessageFromString is used to set email body part, where sendEmail is used to send an email after setting up message,sendTo,from and subject part.

    – keen
    Sep 23 '13 at 6:30











  • your css is working and if you are expecting your images use the full path of image in src of image.

    – Rajeev Ranjan
    Sep 23 '13 at 6:39











  • i know that i need to specify full path of image, as i already said in my question. How can you say that my css is working?

    – keen
    Sep 23 '13 at 6:44














2












2








2








I am developing a website in php and want to send email to a user when user signs up.



I am able to do it successfully.
Even i using html format and it's sending in html format.



I tried this. I know images should be uploaded to server but i will do it later.



$bodyPart = '
<body style="background-color:#FFFFFF;">

<img id="header" style="position:absolute; left:85px; top:50px; " src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>


<img id="cloths" style="position:absolute; left:275px; top:25px;" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>

<font size="7" style="font-family:Times new Roman; position:absolute; left:50px; top:120px;">Thank YOU</font>

<font size="3" style="font-family:Times new Roman;position:absolute;left:50px; top:165px;">For registering with our team </font>

<img id="bag" style ="position:absolute; left:290px; top:345px;"src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>

<img style="position:absolute; left:30px; top:440px; "id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>

</body>

';

$m->setMessageFromString($plainTextBody,$bodyPart);

print_r($ses->sendEmail($m));


I should be getting this output



enter image description here



But i am getting this instead.



enter image description here



But the problem is formatting is not properly done even if it works in my localhost as a independent file. I tried to use External CSS, Internal CSS and inline CSS. But it's not working.



Any example of CSS working with html in sending email would be very helpful.



Thanks In advance.










share|improve this question
















I am developing a website in php and want to send email to a user when user signs up.



I am able to do it successfully.
Even i using html format and it's sending in html format.



I tried this. I know images should be uploaded to server but i will do it later.



$bodyPart = '
<body style="background-color:#FFFFFF;">

<img id="header" style="position:absolute; left:85px; top:50px; " src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>


<img id="cloths" style="position:absolute; left:275px; top:25px;" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>

<font size="7" style="font-family:Times new Roman; position:absolute; left:50px; top:120px;">Thank YOU</font>

<font size="3" style="font-family:Times new Roman;position:absolute;left:50px; top:165px;">For registering with our team </font>

<img id="bag" style ="position:absolute; left:290px; top:345px;"src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>

<img style="position:absolute; left:30px; top:440px; "id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>

</body>

';

$m->setMessageFromString($plainTextBody,$bodyPart);

print_r($ses->sendEmail($m));


I should be getting this output



enter image description here



But i am getting this instead.



enter image description here



But the problem is formatting is not properly done even if it works in my localhost as a independent file. I tried to use External CSS, Internal CSS and inline CSS. But it's not working.



Any example of CSS working with html in sending email would be very helpful.



Thanks In advance.







php email amazon-web-services html-email






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 23 '13 at 6:43









Rajeev Ranjan

4,42522138




4,42522138










asked Sep 23 '13 at 5:59









keenkeen

1,54232154




1,54232154













  • see updated question.

    – keen
    Sep 23 '13 at 6:15











  • we don't know what setMessageFromString() and sendEmail() doing...

    – Rajeev Ranjan
    Sep 23 '13 at 6:18











  • setMessageFromString is used to set email body part, where sendEmail is used to send an email after setting up message,sendTo,from and subject part.

    – keen
    Sep 23 '13 at 6:30











  • your css is working and if you are expecting your images use the full path of image in src of image.

    – Rajeev Ranjan
    Sep 23 '13 at 6:39











  • i know that i need to specify full path of image, as i already said in my question. How can you say that my css is working?

    – keen
    Sep 23 '13 at 6:44



















  • see updated question.

    – keen
    Sep 23 '13 at 6:15











  • we don't know what setMessageFromString() and sendEmail() doing...

    – Rajeev Ranjan
    Sep 23 '13 at 6:18











  • setMessageFromString is used to set email body part, where sendEmail is used to send an email after setting up message,sendTo,from and subject part.

    – keen
    Sep 23 '13 at 6:30











  • your css is working and if you are expecting your images use the full path of image in src of image.

    – Rajeev Ranjan
    Sep 23 '13 at 6:39











  • i know that i need to specify full path of image, as i already said in my question. How can you say that my css is working?

    – keen
    Sep 23 '13 at 6:44

















see updated question.

– keen
Sep 23 '13 at 6:15





see updated question.

– keen
Sep 23 '13 at 6:15













we don't know what setMessageFromString() and sendEmail() doing...

– Rajeev Ranjan
Sep 23 '13 at 6:18





we don't know what setMessageFromString() and sendEmail() doing...

– Rajeev Ranjan
Sep 23 '13 at 6:18













setMessageFromString is used to set email body part, where sendEmail is used to send an email after setting up message,sendTo,from and subject part.

– keen
Sep 23 '13 at 6:30





setMessageFromString is used to set email body part, where sendEmail is used to send an email after setting up message,sendTo,from and subject part.

– keen
Sep 23 '13 at 6:30













your css is working and if you are expecting your images use the full path of image in src of image.

– Rajeev Ranjan
Sep 23 '13 at 6:39





your css is working and if you are expecting your images use the full path of image in src of image.

– Rajeev Ranjan
Sep 23 '13 at 6:39













i know that i need to specify full path of image, as i already said in my question. How can you say that my css is working?

– keen
Sep 23 '13 at 6:44





i know that i need to specify full path of image, as i already said in my question. How can you say that my css is working?

– keen
Sep 23 '13 at 6:44












4 Answers
4






active

oldest

votes


















2














UPDATED
As i assumed, you have just done copy paste.Try following code. Learn HTML basic syntax.




Don't forget to upvote & mark as answered ;)




$bodyPart = ' 

<BODY
<!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=utf-8" />
<title>Untitled Document</title>
</head>

<body style="margin-top:20px;">
<table width="600" cellpadding="0" cellspacing="0" align="center">


<tr>
<td>
<img id="header" src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>
</td>
<td>
<img id="cloths" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>
</td>
</tr>

<tr>
<td>
<font size="7" style="font-family:Times new Roman;">Thank YOU</font>
</td>
<td>
<font size="3" style="font-family:Times new Roman;">For registering with our team </font>
</td>
</tr>
<tr>
<td>
<img id="bag" src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>
</td>
<td>
<img id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>
</td>
</tr>
</table>';

echo $bodyPart;


OLDER
Make it simple. Put one table in your html body & fixed the width.



Your email body should be like following



$body = <<<BODY
<!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=utf-8" />
<title>Untitled Document</title>
</head>

<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
<table width="600" cellpadding="0" cellspacing="0" align="center">
<tr>
<td>=============Your content =========</td>
</tr>
</table>
BODY;

echo $body;





share|improve this answer


























  • it changed output, but still not getting proper formatting as it should be based on the CSS.

    – keen
    Sep 23 '13 at 8:20











  • Note that any email client will not process external css/js . You have to set css inline only. Just create output using simple table. It works for everybody. Might be some issue with your inline css

    – Mayur Kataria
    Sep 23 '13 at 8:20













  • i m using inline css, and it works as independent file,but not while sending an email.

    – keen
    Sep 23 '13 at 8:23











  • remove position absolute from your code & try ... i think its basic html alignment problem.

    – Mayur Kataria
    Sep 23 '13 at 8:26











  • CAn you paste your body variable code

    – Mayur Kataria
    Sep 23 '13 at 8:26



















0














<?php 

$to = 'rajeevranjan@hostname.com';

$subject = 'Test email ';
$headers = 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
$headers .= "From: rajeev ranjan";
$message='<div style="background-color:#FFFFFF;">

<img id="header" style="position:absolute; left:85px; top:50px; " src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>


<img id="cloths" style="position:absolute; left:275px; top:25px;" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>

<font size="7" style="font-family:Times new Roman; position:absolute; left:50px; top:120px;">Thank YOU</font>

<font size="3" style="font-family:Times new Roman;position:absolute;left:50px; top:165px;">For registering with our team </font>

<img id="bag" style ="position:absolute; left:290px; top:345px;"src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>

<img style="position:absolute; left:30px; top:440px; "id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>

</div>

';
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>





share|improve this answer



















  • 1





    but my main problem is it doesn't work with Amazon service. i am not getting proper output. As you can see in my question. Any idea why?

    – keen
    Sep 23 '13 at 7:16











  • I know about the images and i will upload it soon, but even CSS is not working.

    – keen
    Sep 23 '13 at 7:17











  • I tried to use your script, just changed the to and from. And even in this i m not getting proper output. will you please post your received email screenshot ?

    – keen
    Sep 23 '13 at 7:41











  • proper output relates to css i am not good in writing css.An HTML expert can do this for you.

    – Rajeev Ranjan
    Sep 23 '13 at 7:44











  • bt you said that you are getting proper output in email

    – keen
    Sep 23 '13 at 7:46



















0














Post your code..



But i think the Problem is your Content-Type.



Check this:



Content-type: text/html; charset=iso-8859-1rn


text/html is necessary..



UPDATE:



The path is not correct.



images/logo.jpg


Upload the image to the server (or imagehoster) and insert the whole link.



UPDATE 2



I think i have the solution:



The first parameter from setMessageFromString() is the plain Text. The second parameter requires the html content. If you want to sent HTML - Email, check this:



$m->setMessageFromString($plainTextBody, $HTMLBody); 





share|improve this answer


























  • see updated question.

    – keen
    Sep 23 '13 at 6:16











  • show us the code from setMessageFromString()..

    – q0re
    Sep 23 '13 at 6:23











  • it's a built-in function in SES(simple email service) provided by amazon.

    – keen
    Sep 23 '13 at 6:39













  • i think i have the solution, check update ..

    – q0re
    Sep 23 '13 at 7:39











  • i knw tht. But if tht the prblm only images should not be displayed why it changes formatting. see my question again for more details.

    – keen
    Sep 23 '13 at 7:42



















0














My example here is using the Boto3 library for Python 3 but I think it could still translate into this PHP question mainly because the core of the problem is not PHP specific but rather the HTML inside your HTML_BODY field for SES and that is language agnostic so my example here should help.



This code successfully sends to my email address, formatted exactly how it appears in the example on W3 Schools here



HTML Example:



<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
width: 100%;
}

th, td {
text-align: left;
padding: 8px;
}

tr:nth-child(even){background-color: #f2f2f2}
</style>
</head>
<body>

<h2>Responsive Table</h2>
<p>A responsive table will display a horizontal scroll bar if the screen is too
small to display the full content. Resize the browser window to see the effect:</p>
<p>To create a responsive table, add a container element (like div) with <strong>overflow-x:auto</strong> around the table element:</p>

<div style="overflow-x:auto;">
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
</tr>
<tr>
<td>Adam</td>
<td>Johnson</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
</tr>
</table>
</div>

</body>
</html>


AWS SES Example Using The Above HTML:



#Your Imports go here
import boto3

# Replace sender@example.com with your "From" address.
# This address must be verified with Amazon SES.
SENDER = "the_email_address_of_who_is_sending_this_email_out@gmail.com"

# Replace recipient@example.com with a "To" address. If your account
# is still in the sandbox, this address must be verified.
RECIPIENT = "the_email_address_of_who_will_be_receiving_this_email@gmail.com"

# Specify a configuration set. If you do not want to use a configuration
# set, comment the following variable, and the
# ConfigurationSetName=CONFIGURATION_SET argument below.
# CONFIGURATION_SET = "ConfigSet"

# If necessary, replace us-west-2 with the AWS Region you're using for Amazon SES.
AWS_REGION = "us-east-1"

# The subject line for the email.
SUBJECT = "ARL Data Lake"

# The email body for recipients with non-HTML email clients.
# BODY_TEXT = ("Amazon SES Test (Python)rn"
# "This email was sent with Amazon SES using the "
# "AWS SDK for Python (Boto)."
# )
BODY_TEXT = str(records)

# The HTML body of the email.

BODY_HTML = """<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
width: 100%;
}

th, td {
text-align: left;
padding: 8px;
}

tr:nth-child(even){background-color: #f2f2f2}
</style>
</head>
<body>

<h2>Responsive Table</h2>
<p>A responsive table will display a horizontal scroll bar if the screen is too
small to display the full content. Resize the browser window to see the effect:</p>
<p>To create a responsive table, add a container element (like div) with <strong>overflow-x:auto</strong> around the table element:</p>

<div style="overflow-x:auto;">
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
<th>Points</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
<td>94</td>
</tr>
<tr>
<td>Adam</td>
<td>Johnson</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
<td>67</td>
</tr>
</table>
</div>

</body>
</html>"""

# The character encoding for the email.
CHARSET = "UTF-8"

# Create a new SES resource and specify a region.
client = boto3.client('ses', region_name=AWS_REGION)

# Try to send the email.
try:
# Provide the contents of the email.
response = client.send_email(
Destination={
'ToAddresses': [
RECIPIENT,
],
},
Message={
'Body': {
'Html': {
'Charset': CHARSET,
'Data': BODY_HTML,
},
'Text': {
'Charset': CHARSET,
'Data': BODY_TEXT,
},
},
'Subject': {
'Charset': CHARSET,
'Data': SUBJECT,
},
},
Source=SENDER,
# If you are not using a configuration set, comment or delete the
# following line
# ConfigurationSetName=CONFIGURATION_SET,
)
# Display an error if something goes wrong.
except Exception as e:
print(e.response['Error']['Message'])
else:
print("Email sent! Message ID:"),
print(response['MessageId'])


The Email Result:



enter image description here



Sources & Further Help/Examples:




  • Python to PHP: Converting Python Code to PHP


  • AWS Boto3 Python 3.6 SES Example: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-python.html


  • Basic HTML CSS For Tables: https://www.w3schools.com/css/css_table.asp


  • More AWS SES Help: https://aws.amazon.com/ses/getting-started/



Note:



To run this example easily I recommend setting up a quick Cloud9 IDE in AWS, installing Python 3 on it, copy and paste my code into it, then click run. If your Cloud9 has the proper roles and permissions to use SES then it should work. Also note that Cloud9 is just running on top of an EC2-Instance so you can SSH into it (directly from the Management Console on your browser which is nice) and run something like "sudo yum install python-3.6" and manually run the code using "sudo touch code_example.py", "sudo chmod 755 code_example.py", "sudo vi code_example.py", then hit the "i" key which stands for insert, then right click and for my SSH client that pastes the code I had copied onto my clipboard into the SSH's text editor for VI, then click "ESC" to get out of insert mode, then click ":wq" and click enter which stands for "write" and then "quit", then to run it do "python3 code_example.py". If you successfully installed Python it should work. But like I said it's easier to just use Cloud9, open the IDE for Cloud9, create a new Python file, paste the code in, then run it as Python 3 there's a button that does it just like any normal IDE.



enter image description here






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18952620%2fcss-not-working-in-email-sending-using-aws%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    UPDATED
    As i assumed, you have just done copy paste.Try following code. Learn HTML basic syntax.




    Don't forget to upvote & mark as answered ;)




    $bodyPart = ' 

    <BODY
    <!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=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body style="margin-top:20px;">
    <table width="600" cellpadding="0" cellspacing="0" align="center">


    <tr>
    <td>
    <img id="header" src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>
    </td>
    <td>
    <img id="cloths" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>
    </td>
    </tr>

    <tr>
    <td>
    <font size="7" style="font-family:Times new Roman;">Thank YOU</font>
    </td>
    <td>
    <font size="3" style="font-family:Times new Roman;">For registering with our team </font>
    </td>
    </tr>
    <tr>
    <td>
    <img id="bag" src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>
    </td>
    <td>
    <img id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>
    </td>
    </tr>
    </table>';

    echo $bodyPart;


    OLDER
    Make it simple. Put one table in your html body & fixed the width.



    Your email body should be like following



    $body = <<<BODY
    <!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=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
    <table width="600" cellpadding="0" cellspacing="0" align="center">
    <tr>
    <td>=============Your content =========</td>
    </tr>
    </table>
    BODY;

    echo $body;





    share|improve this answer


























    • it changed output, but still not getting proper formatting as it should be based on the CSS.

      – keen
      Sep 23 '13 at 8:20











    • Note that any email client will not process external css/js . You have to set css inline only. Just create output using simple table. It works for everybody. Might be some issue with your inline css

      – Mayur Kataria
      Sep 23 '13 at 8:20













    • i m using inline css, and it works as independent file,but not while sending an email.

      – keen
      Sep 23 '13 at 8:23











    • remove position absolute from your code & try ... i think its basic html alignment problem.

      – Mayur Kataria
      Sep 23 '13 at 8:26











    • CAn you paste your body variable code

      – Mayur Kataria
      Sep 23 '13 at 8:26
















    2














    UPDATED
    As i assumed, you have just done copy paste.Try following code. Learn HTML basic syntax.




    Don't forget to upvote & mark as answered ;)




    $bodyPart = ' 

    <BODY
    <!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=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body style="margin-top:20px;">
    <table width="600" cellpadding="0" cellspacing="0" align="center">


    <tr>
    <td>
    <img id="header" src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>
    </td>
    <td>
    <img id="cloths" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>
    </td>
    </tr>

    <tr>
    <td>
    <font size="7" style="font-family:Times new Roman;">Thank YOU</font>
    </td>
    <td>
    <font size="3" style="font-family:Times new Roman;">For registering with our team </font>
    </td>
    </tr>
    <tr>
    <td>
    <img id="bag" src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>
    </td>
    <td>
    <img id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>
    </td>
    </tr>
    </table>';

    echo $bodyPart;


    OLDER
    Make it simple. Put one table in your html body & fixed the width.



    Your email body should be like following



    $body = <<<BODY
    <!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=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
    <table width="600" cellpadding="0" cellspacing="0" align="center">
    <tr>
    <td>=============Your content =========</td>
    </tr>
    </table>
    BODY;

    echo $body;





    share|improve this answer


























    • it changed output, but still not getting proper formatting as it should be based on the CSS.

      – keen
      Sep 23 '13 at 8:20











    • Note that any email client will not process external css/js . You have to set css inline only. Just create output using simple table. It works for everybody. Might be some issue with your inline css

      – Mayur Kataria
      Sep 23 '13 at 8:20













    • i m using inline css, and it works as independent file,but not while sending an email.

      – keen
      Sep 23 '13 at 8:23











    • remove position absolute from your code & try ... i think its basic html alignment problem.

      – Mayur Kataria
      Sep 23 '13 at 8:26











    • CAn you paste your body variable code

      – Mayur Kataria
      Sep 23 '13 at 8:26














    2












    2








    2







    UPDATED
    As i assumed, you have just done copy paste.Try following code. Learn HTML basic syntax.




    Don't forget to upvote & mark as answered ;)




    $bodyPart = ' 

    <BODY
    <!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=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body style="margin-top:20px;">
    <table width="600" cellpadding="0" cellspacing="0" align="center">


    <tr>
    <td>
    <img id="header" src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>
    </td>
    <td>
    <img id="cloths" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>
    </td>
    </tr>

    <tr>
    <td>
    <font size="7" style="font-family:Times new Roman;">Thank YOU</font>
    </td>
    <td>
    <font size="3" style="font-family:Times new Roman;">For registering with our team </font>
    </td>
    </tr>
    <tr>
    <td>
    <img id="bag" src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>
    </td>
    <td>
    <img id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>
    </td>
    </tr>
    </table>';

    echo $bodyPart;


    OLDER
    Make it simple. Put one table in your html body & fixed the width.



    Your email body should be like following



    $body = <<<BODY
    <!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=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
    <table width="600" cellpadding="0" cellspacing="0" align="center">
    <tr>
    <td>=============Your content =========</td>
    </tr>
    </table>
    BODY;

    echo $body;





    share|improve this answer















    UPDATED
    As i assumed, you have just done copy paste.Try following code. Learn HTML basic syntax.




    Don't forget to upvote & mark as answered ;)




    $bodyPart = ' 

    <BODY
    <!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=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body style="margin-top:20px;">
    <table width="600" cellpadding="0" cellspacing="0" align="center">


    <tr>
    <td>
    <img id="header" src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>
    </td>
    <td>
    <img id="cloths" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>
    </td>
    </tr>

    <tr>
    <td>
    <font size="7" style="font-family:Times new Roman;">Thank YOU</font>
    </td>
    <td>
    <font size="3" style="font-family:Times new Roman;">For registering with our team </font>
    </td>
    </tr>
    <tr>
    <td>
    <img id="bag" src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>
    </td>
    <td>
    <img id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>
    </td>
    </tr>
    </table>';

    echo $bodyPart;


    OLDER
    Make it simple. Put one table in your html body & fixed the width.



    Your email body should be like following



    $body = <<<BODY
    <!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=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
    <table width="600" cellpadding="0" cellspacing="0" align="center">
    <tr>
    <td>=============Your content =========</td>
    </tr>
    </table>
    BODY;

    echo $body;






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 23 '13 at 10:57

























    answered Sep 23 '13 at 8:12









    Mayur KatariaMayur Kataria

    419712




    419712













    • it changed output, but still not getting proper formatting as it should be based on the CSS.

      – keen
      Sep 23 '13 at 8:20











    • Note that any email client will not process external css/js . You have to set css inline only. Just create output using simple table. It works for everybody. Might be some issue with your inline css

      – Mayur Kataria
      Sep 23 '13 at 8:20













    • i m using inline css, and it works as independent file,but not while sending an email.

      – keen
      Sep 23 '13 at 8:23











    • remove position absolute from your code & try ... i think its basic html alignment problem.

      – Mayur Kataria
      Sep 23 '13 at 8:26











    • CAn you paste your body variable code

      – Mayur Kataria
      Sep 23 '13 at 8:26



















    • it changed output, but still not getting proper formatting as it should be based on the CSS.

      – keen
      Sep 23 '13 at 8:20











    • Note that any email client will not process external css/js . You have to set css inline only. Just create output using simple table. It works for everybody. Might be some issue with your inline css

      – Mayur Kataria
      Sep 23 '13 at 8:20













    • i m using inline css, and it works as independent file,but not while sending an email.

      – keen
      Sep 23 '13 at 8:23











    • remove position absolute from your code & try ... i think its basic html alignment problem.

      – Mayur Kataria
      Sep 23 '13 at 8:26











    • CAn you paste your body variable code

      – Mayur Kataria
      Sep 23 '13 at 8:26

















    it changed output, but still not getting proper formatting as it should be based on the CSS.

    – keen
    Sep 23 '13 at 8:20





    it changed output, but still not getting proper formatting as it should be based on the CSS.

    – keen
    Sep 23 '13 at 8:20













    Note that any email client will not process external css/js . You have to set css inline only. Just create output using simple table. It works for everybody. Might be some issue with your inline css

    – Mayur Kataria
    Sep 23 '13 at 8:20







    Note that any email client will not process external css/js . You have to set css inline only. Just create output using simple table. It works for everybody. Might be some issue with your inline css

    – Mayur Kataria
    Sep 23 '13 at 8:20















    i m using inline css, and it works as independent file,but not while sending an email.

    – keen
    Sep 23 '13 at 8:23





    i m using inline css, and it works as independent file,but not while sending an email.

    – keen
    Sep 23 '13 at 8:23













    remove position absolute from your code & try ... i think its basic html alignment problem.

    – Mayur Kataria
    Sep 23 '13 at 8:26





    remove position absolute from your code & try ... i think its basic html alignment problem.

    – Mayur Kataria
    Sep 23 '13 at 8:26













    CAn you paste your body variable code

    – Mayur Kataria
    Sep 23 '13 at 8:26





    CAn you paste your body variable code

    – Mayur Kataria
    Sep 23 '13 at 8:26













    0














    <?php 

    $to = 'rajeevranjan@hostname.com';

    $subject = 'Test email ';
    $headers = 'MIME-Version: 1.0' . "rn";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
    $headers .= "From: rajeev ranjan";
    $message='<div style="background-color:#FFFFFF;">

    <img id="header" style="position:absolute; left:85px; top:50px; " src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>


    <img id="cloths" style="position:absolute; left:275px; top:25px;" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>

    <font size="7" style="font-family:Times new Roman; position:absolute; left:50px; top:120px;">Thank YOU</font>

    <font size="3" style="font-family:Times new Roman;position:absolute;left:50px; top:165px;">For registering with our team </font>

    <img id="bag" style ="position:absolute; left:290px; top:345px;"src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>

    <img style="position:absolute; left:30px; top:440px; "id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>

    </div>

    ';
    //send the email
    $mail_sent = @mail( $to, $subject, $message, $headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
    echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>





    share|improve this answer



















    • 1





      but my main problem is it doesn't work with Amazon service. i am not getting proper output. As you can see in my question. Any idea why?

      – keen
      Sep 23 '13 at 7:16











    • I know about the images and i will upload it soon, but even CSS is not working.

      – keen
      Sep 23 '13 at 7:17











    • I tried to use your script, just changed the to and from. And even in this i m not getting proper output. will you please post your received email screenshot ?

      – keen
      Sep 23 '13 at 7:41











    • proper output relates to css i am not good in writing css.An HTML expert can do this for you.

      – Rajeev Ranjan
      Sep 23 '13 at 7:44











    • bt you said that you are getting proper output in email

      – keen
      Sep 23 '13 at 7:46
















    0














    <?php 

    $to = 'rajeevranjan@hostname.com';

    $subject = 'Test email ';
    $headers = 'MIME-Version: 1.0' . "rn";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
    $headers .= "From: rajeev ranjan";
    $message='<div style="background-color:#FFFFFF;">

    <img id="header" style="position:absolute; left:85px; top:50px; " src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>


    <img id="cloths" style="position:absolute; left:275px; top:25px;" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>

    <font size="7" style="font-family:Times new Roman; position:absolute; left:50px; top:120px;">Thank YOU</font>

    <font size="3" style="font-family:Times new Roman;position:absolute;left:50px; top:165px;">For registering with our team </font>

    <img id="bag" style ="position:absolute; left:290px; top:345px;"src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>

    <img style="position:absolute; left:30px; top:440px; "id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>

    </div>

    ';
    //send the email
    $mail_sent = @mail( $to, $subject, $message, $headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
    echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>





    share|improve this answer



















    • 1





      but my main problem is it doesn't work with Amazon service. i am not getting proper output. As you can see in my question. Any idea why?

      – keen
      Sep 23 '13 at 7:16











    • I know about the images and i will upload it soon, but even CSS is not working.

      – keen
      Sep 23 '13 at 7:17











    • I tried to use your script, just changed the to and from. And even in this i m not getting proper output. will you please post your received email screenshot ?

      – keen
      Sep 23 '13 at 7:41











    • proper output relates to css i am not good in writing css.An HTML expert can do this for you.

      – Rajeev Ranjan
      Sep 23 '13 at 7:44











    • bt you said that you are getting proper output in email

      – keen
      Sep 23 '13 at 7:46














    0












    0








    0







    <?php 

    $to = 'rajeevranjan@hostname.com';

    $subject = 'Test email ';
    $headers = 'MIME-Version: 1.0' . "rn";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
    $headers .= "From: rajeev ranjan";
    $message='<div style="background-color:#FFFFFF;">

    <img id="header" style="position:absolute; left:85px; top:50px; " src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>


    <img id="cloths" style="position:absolute; left:275px; top:25px;" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>

    <font size="7" style="font-family:Times new Roman; position:absolute; left:50px; top:120px;">Thank YOU</font>

    <font size="3" style="font-family:Times new Roman;position:absolute;left:50px; top:165px;">For registering with our team </font>

    <img id="bag" style ="position:absolute; left:290px; top:345px;"src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>

    <img style="position:absolute; left:30px; top:440px; "id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>

    </div>

    ';
    //send the email
    $mail_sent = @mail( $to, $subject, $message, $headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
    echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>





    share|improve this answer













    <?php 

    $to = 'rajeevranjan@hostname.com';

    $subject = 'Test email ';
    $headers = 'MIME-Version: 1.0' . "rn";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
    $headers .= "From: rajeev ranjan";
    $message='<div style="background-color:#FFFFFF;">

    <img id="header" style="position:absolute; left:85px; top:50px; " src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a>


    <img id="cloths" style="position:absolute; left:275px; top:25px;" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a>

    <font size="7" style="font-family:Times new Roman; position:absolute; left:50px; top:120px;">Thank YOU</font>

    <font size="3" style="font-family:Times new Roman;position:absolute;left:50px; top:165px;">For registering with our team </font>

    <img id="bag" style ="position:absolute; left:290px; top:345px;"src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a>

    <img style="position:absolute; left:30px; top:440px; "id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a>

    </div>

    ';
    //send the email
    $mail_sent = @mail( $to, $subject, $message, $headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
    echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Sep 23 '13 at 7:03









    Rajeev RanjanRajeev Ranjan

    4,42522138




    4,42522138








    • 1





      but my main problem is it doesn't work with Amazon service. i am not getting proper output. As you can see in my question. Any idea why?

      – keen
      Sep 23 '13 at 7:16











    • I know about the images and i will upload it soon, but even CSS is not working.

      – keen
      Sep 23 '13 at 7:17











    • I tried to use your script, just changed the to and from. And even in this i m not getting proper output. will you please post your received email screenshot ?

      – keen
      Sep 23 '13 at 7:41











    • proper output relates to css i am not good in writing css.An HTML expert can do this for you.

      – Rajeev Ranjan
      Sep 23 '13 at 7:44











    • bt you said that you are getting proper output in email

      – keen
      Sep 23 '13 at 7:46














    • 1





      but my main problem is it doesn't work with Amazon service. i am not getting proper output. As you can see in my question. Any idea why?

      – keen
      Sep 23 '13 at 7:16











    • I know about the images and i will upload it soon, but even CSS is not working.

      – keen
      Sep 23 '13 at 7:17











    • I tried to use your script, just changed the to and from. And even in this i m not getting proper output. will you please post your received email screenshot ?

      – keen
      Sep 23 '13 at 7:41











    • proper output relates to css i am not good in writing css.An HTML expert can do this for you.

      – Rajeev Ranjan
      Sep 23 '13 at 7:44











    • bt you said that you are getting proper output in email

      – keen
      Sep 23 '13 at 7:46








    1




    1





    but my main problem is it doesn't work with Amazon service. i am not getting proper output. As you can see in my question. Any idea why?

    – keen
    Sep 23 '13 at 7:16





    but my main problem is it doesn't work with Amazon service. i am not getting proper output. As you can see in my question. Any idea why?

    – keen
    Sep 23 '13 at 7:16













    I know about the images and i will upload it soon, but even CSS is not working.

    – keen
    Sep 23 '13 at 7:17





    I know about the images and i will upload it soon, but even CSS is not working.

    – keen
    Sep 23 '13 at 7:17













    I tried to use your script, just changed the to and from. And even in this i m not getting proper output. will you please post your received email screenshot ?

    – keen
    Sep 23 '13 at 7:41





    I tried to use your script, just changed the to and from. And even in this i m not getting proper output. will you please post your received email screenshot ?

    – keen
    Sep 23 '13 at 7:41













    proper output relates to css i am not good in writing css.An HTML expert can do this for you.

    – Rajeev Ranjan
    Sep 23 '13 at 7:44





    proper output relates to css i am not good in writing css.An HTML expert can do this for you.

    – Rajeev Ranjan
    Sep 23 '13 at 7:44













    bt you said that you are getting proper output in email

    – keen
    Sep 23 '13 at 7:46





    bt you said that you are getting proper output in email

    – keen
    Sep 23 '13 at 7:46











    0














    Post your code..



    But i think the Problem is your Content-Type.



    Check this:



    Content-type: text/html; charset=iso-8859-1rn


    text/html is necessary..



    UPDATE:



    The path is not correct.



    images/logo.jpg


    Upload the image to the server (or imagehoster) and insert the whole link.



    UPDATE 2



    I think i have the solution:



    The first parameter from setMessageFromString() is the plain Text. The second parameter requires the html content. If you want to sent HTML - Email, check this:



    $m->setMessageFromString($plainTextBody, $HTMLBody); 





    share|improve this answer


























    • see updated question.

      – keen
      Sep 23 '13 at 6:16











    • show us the code from setMessageFromString()..

      – q0re
      Sep 23 '13 at 6:23











    • it's a built-in function in SES(simple email service) provided by amazon.

      – keen
      Sep 23 '13 at 6:39













    • i think i have the solution, check update ..

      – q0re
      Sep 23 '13 at 7:39











    • i knw tht. But if tht the prblm only images should not be displayed why it changes formatting. see my question again for more details.

      – keen
      Sep 23 '13 at 7:42
















    0














    Post your code..



    But i think the Problem is your Content-Type.



    Check this:



    Content-type: text/html; charset=iso-8859-1rn


    text/html is necessary..



    UPDATE:



    The path is not correct.



    images/logo.jpg


    Upload the image to the server (or imagehoster) and insert the whole link.



    UPDATE 2



    I think i have the solution:



    The first parameter from setMessageFromString() is the plain Text. The second parameter requires the html content. If you want to sent HTML - Email, check this:



    $m->setMessageFromString($plainTextBody, $HTMLBody); 





    share|improve this answer


























    • see updated question.

      – keen
      Sep 23 '13 at 6:16











    • show us the code from setMessageFromString()..

      – q0re
      Sep 23 '13 at 6:23











    • it's a built-in function in SES(simple email service) provided by amazon.

      – keen
      Sep 23 '13 at 6:39













    • i think i have the solution, check update ..

      – q0re
      Sep 23 '13 at 7:39











    • i knw tht. But if tht the prblm only images should not be displayed why it changes formatting. see my question again for more details.

      – keen
      Sep 23 '13 at 7:42














    0












    0








    0







    Post your code..



    But i think the Problem is your Content-Type.



    Check this:



    Content-type: text/html; charset=iso-8859-1rn


    text/html is necessary..



    UPDATE:



    The path is not correct.



    images/logo.jpg


    Upload the image to the server (or imagehoster) and insert the whole link.



    UPDATE 2



    I think i have the solution:



    The first parameter from setMessageFromString() is the plain Text. The second parameter requires the html content. If you want to sent HTML - Email, check this:



    $m->setMessageFromString($plainTextBody, $HTMLBody); 





    share|improve this answer















    Post your code..



    But i think the Problem is your Content-Type.



    Check this:



    Content-type: text/html; charset=iso-8859-1rn


    text/html is necessary..



    UPDATE:



    The path is not correct.



    images/logo.jpg


    Upload the image to the server (or imagehoster) and insert the whole link.



    UPDATE 2



    I think i have the solution:



    The first parameter from setMessageFromString() is the plain Text. The second parameter requires the html content. If you want to sent HTML - Email, check this:



    $m->setMessageFromString($plainTextBody, $HTMLBody); 






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 23 '13 at 7:42

























    answered Sep 23 '13 at 6:10









    q0req0re

    1,1041531




    1,1041531













    • see updated question.

      – keen
      Sep 23 '13 at 6:16











    • show us the code from setMessageFromString()..

      – q0re
      Sep 23 '13 at 6:23











    • it's a built-in function in SES(simple email service) provided by amazon.

      – keen
      Sep 23 '13 at 6:39













    • i think i have the solution, check update ..

      – q0re
      Sep 23 '13 at 7:39











    • i knw tht. But if tht the prblm only images should not be displayed why it changes formatting. see my question again for more details.

      – keen
      Sep 23 '13 at 7:42



















    • see updated question.

      – keen
      Sep 23 '13 at 6:16











    • show us the code from setMessageFromString()..

      – q0re
      Sep 23 '13 at 6:23











    • it's a built-in function in SES(simple email service) provided by amazon.

      – keen
      Sep 23 '13 at 6:39













    • i think i have the solution, check update ..

      – q0re
      Sep 23 '13 at 7:39











    • i knw tht. But if tht the prblm only images should not be displayed why it changes formatting. see my question again for more details.

      – keen
      Sep 23 '13 at 7:42

















    see updated question.

    – keen
    Sep 23 '13 at 6:16





    see updated question.

    – keen
    Sep 23 '13 at 6:16













    show us the code from setMessageFromString()..

    – q0re
    Sep 23 '13 at 6:23





    show us the code from setMessageFromString()..

    – q0re
    Sep 23 '13 at 6:23













    it's a built-in function in SES(simple email service) provided by amazon.

    – keen
    Sep 23 '13 at 6:39







    it's a built-in function in SES(simple email service) provided by amazon.

    – keen
    Sep 23 '13 at 6:39















    i think i have the solution, check update ..

    – q0re
    Sep 23 '13 at 7:39





    i think i have the solution, check update ..

    – q0re
    Sep 23 '13 at 7:39













    i knw tht. But if tht the prblm only images should not be displayed why it changes formatting. see my question again for more details.

    – keen
    Sep 23 '13 at 7:42





    i knw tht. But if tht the prblm only images should not be displayed why it changes formatting. see my question again for more details.

    – keen
    Sep 23 '13 at 7:42











    0














    My example here is using the Boto3 library for Python 3 but I think it could still translate into this PHP question mainly because the core of the problem is not PHP specific but rather the HTML inside your HTML_BODY field for SES and that is language agnostic so my example here should help.



    This code successfully sends to my email address, formatted exactly how it appears in the example on W3 Schools here



    HTML Example:



    <!DOCTYPE html>
    <html>
    <head>
    <style>
    table {
    border-collapse: collapse;
    width: 100%;
    }

    th, td {
    text-align: left;
    padding: 8px;
    }

    tr:nth-child(even){background-color: #f2f2f2}
    </style>
    </head>
    <body>

    <h2>Responsive Table</h2>
    <p>A responsive table will display a horizontal scroll bar if the screen is too
    small to display the full content. Resize the browser window to see the effect:</p>
    <p>To create a responsive table, add a container element (like div) with <strong>overflow-x:auto</strong> around the table element:</p>

    <div style="overflow-x:auto;">
    <table>
    <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    </tr>
    <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    </tr>
    <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    </tr>
    <tr>
    <td>Adam</td>
    <td>Johnson</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    </tr>
    </table>
    </div>

    </body>
    </html>


    AWS SES Example Using The Above HTML:



    #Your Imports go here
    import boto3

    # Replace sender@example.com with your "From" address.
    # This address must be verified with Amazon SES.
    SENDER = "the_email_address_of_who_is_sending_this_email_out@gmail.com"

    # Replace recipient@example.com with a "To" address. If your account
    # is still in the sandbox, this address must be verified.
    RECIPIENT = "the_email_address_of_who_will_be_receiving_this_email@gmail.com"

    # Specify a configuration set. If you do not want to use a configuration
    # set, comment the following variable, and the
    # ConfigurationSetName=CONFIGURATION_SET argument below.
    # CONFIGURATION_SET = "ConfigSet"

    # If necessary, replace us-west-2 with the AWS Region you're using for Amazon SES.
    AWS_REGION = "us-east-1"

    # The subject line for the email.
    SUBJECT = "ARL Data Lake"

    # The email body for recipients with non-HTML email clients.
    # BODY_TEXT = ("Amazon SES Test (Python)rn"
    # "This email was sent with Amazon SES using the "
    # "AWS SDK for Python (Boto)."
    # )
    BODY_TEXT = str(records)

    # The HTML body of the email.

    BODY_HTML = """<!DOCTYPE html>
    <html>
    <head>
    <style>
    table {
    border-collapse: collapse;
    width: 100%;
    }

    th, td {
    text-align: left;
    padding: 8px;
    }

    tr:nth-child(even){background-color: #f2f2f2}
    </style>
    </head>
    <body>

    <h2>Responsive Table</h2>
    <p>A responsive table will display a horizontal scroll bar if the screen is too
    small to display the full content. Resize the browser window to see the effect:</p>
    <p>To create a responsive table, add a container element (like div) with <strong>overflow-x:auto</strong> around the table element:</p>

    <div style="overflow-x:auto;">
    <table>
    <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    <th>Points</th>
    </tr>
    <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    </tr>
    <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    <td>94</td>
    </tr>
    <tr>
    <td>Adam</td>
    <td>Johnson</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    <td>67</td>
    </tr>
    </table>
    </div>

    </body>
    </html>"""

    # The character encoding for the email.
    CHARSET = "UTF-8"

    # Create a new SES resource and specify a region.
    client = boto3.client('ses', region_name=AWS_REGION)

    # Try to send the email.
    try:
    # Provide the contents of the email.
    response = client.send_email(
    Destination={
    'ToAddresses': [
    RECIPIENT,
    ],
    },
    Message={
    'Body': {
    'Html': {
    'Charset': CHARSET,
    'Data': BODY_HTML,
    },
    'Text': {
    'Charset': CHARSET,
    'Data': BODY_TEXT,
    },
    },
    'Subject': {
    'Charset': CHARSET,
    'Data': SUBJECT,
    },
    },
    Source=SENDER,
    # If you are not using a configuration set, comment or delete the
    # following line
    # ConfigurationSetName=CONFIGURATION_SET,
    )
    # Display an error if something goes wrong.
    except Exception as e:
    print(e.response['Error']['Message'])
    else:
    print("Email sent! Message ID:"),
    print(response['MessageId'])


    The Email Result:



    enter image description here



    Sources & Further Help/Examples:




    • Python to PHP: Converting Python Code to PHP


    • AWS Boto3 Python 3.6 SES Example: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-python.html


    • Basic HTML CSS For Tables: https://www.w3schools.com/css/css_table.asp


    • More AWS SES Help: https://aws.amazon.com/ses/getting-started/



    Note:



    To run this example easily I recommend setting up a quick Cloud9 IDE in AWS, installing Python 3 on it, copy and paste my code into it, then click run. If your Cloud9 has the proper roles and permissions to use SES then it should work. Also note that Cloud9 is just running on top of an EC2-Instance so you can SSH into it (directly from the Management Console on your browser which is nice) and run something like "sudo yum install python-3.6" and manually run the code using "sudo touch code_example.py", "sudo chmod 755 code_example.py", "sudo vi code_example.py", then hit the "i" key which stands for insert, then right click and for my SSH client that pastes the code I had copied onto my clipboard into the SSH's text editor for VI, then click "ESC" to get out of insert mode, then click ":wq" and click enter which stands for "write" and then "quit", then to run it do "python3 code_example.py". If you successfully installed Python it should work. But like I said it's easier to just use Cloud9, open the IDE for Cloud9, create a new Python file, paste the code in, then run it as Python 3 there's a button that does it just like any normal IDE.



    enter image description here






    share|improve this answer






























      0














      My example here is using the Boto3 library for Python 3 but I think it could still translate into this PHP question mainly because the core of the problem is not PHP specific but rather the HTML inside your HTML_BODY field for SES and that is language agnostic so my example here should help.



      This code successfully sends to my email address, formatted exactly how it appears in the example on W3 Schools here



      HTML Example:



      <!DOCTYPE html>
      <html>
      <head>
      <style>
      table {
      border-collapse: collapse;
      width: 100%;
      }

      th, td {
      text-align: left;
      padding: 8px;
      }

      tr:nth-child(even){background-color: #f2f2f2}
      </style>
      </head>
      <body>

      <h2>Responsive Table</h2>
      <p>A responsive table will display a horizontal scroll bar if the screen is too
      small to display the full content. Resize the browser window to see the effect:</p>
      <p>To create a responsive table, add a container element (like div) with <strong>overflow-x:auto</strong> around the table element:</p>

      <div style="overflow-x:auto;">
      <table>
      <tr>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      </tr>
      <tr>
      <td>Jill</td>
      <td>Smith</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      </tr>
      <tr>
      <td>Eve</td>
      <td>Jackson</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      </tr>
      <tr>
      <td>Adam</td>
      <td>Johnson</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      </tr>
      </table>
      </div>

      </body>
      </html>


      AWS SES Example Using The Above HTML:



      #Your Imports go here
      import boto3

      # Replace sender@example.com with your "From" address.
      # This address must be verified with Amazon SES.
      SENDER = "the_email_address_of_who_is_sending_this_email_out@gmail.com"

      # Replace recipient@example.com with a "To" address. If your account
      # is still in the sandbox, this address must be verified.
      RECIPIENT = "the_email_address_of_who_will_be_receiving_this_email@gmail.com"

      # Specify a configuration set. If you do not want to use a configuration
      # set, comment the following variable, and the
      # ConfigurationSetName=CONFIGURATION_SET argument below.
      # CONFIGURATION_SET = "ConfigSet"

      # If necessary, replace us-west-2 with the AWS Region you're using for Amazon SES.
      AWS_REGION = "us-east-1"

      # The subject line for the email.
      SUBJECT = "ARL Data Lake"

      # The email body for recipients with non-HTML email clients.
      # BODY_TEXT = ("Amazon SES Test (Python)rn"
      # "This email was sent with Amazon SES using the "
      # "AWS SDK for Python (Boto)."
      # )
      BODY_TEXT = str(records)

      # The HTML body of the email.

      BODY_HTML = """<!DOCTYPE html>
      <html>
      <head>
      <style>
      table {
      border-collapse: collapse;
      width: 100%;
      }

      th, td {
      text-align: left;
      padding: 8px;
      }

      tr:nth-child(even){background-color: #f2f2f2}
      </style>
      </head>
      <body>

      <h2>Responsive Table</h2>
      <p>A responsive table will display a horizontal scroll bar if the screen is too
      small to display the full content. Resize the browser window to see the effect:</p>
      <p>To create a responsive table, add a container element (like div) with <strong>overflow-x:auto</strong> around the table element:</p>

      <div style="overflow-x:auto;">
      <table>
      <tr>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      <th>Points</th>
      </tr>
      <tr>
      <td>Jill</td>
      <td>Smith</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      <td>50</td>
      </tr>
      <tr>
      <td>Eve</td>
      <td>Jackson</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      <td>94</td>
      </tr>
      <tr>
      <td>Adam</td>
      <td>Johnson</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      <td>67</td>
      </tr>
      </table>
      </div>

      </body>
      </html>"""

      # The character encoding for the email.
      CHARSET = "UTF-8"

      # Create a new SES resource and specify a region.
      client = boto3.client('ses', region_name=AWS_REGION)

      # Try to send the email.
      try:
      # Provide the contents of the email.
      response = client.send_email(
      Destination={
      'ToAddresses': [
      RECIPIENT,
      ],
      },
      Message={
      'Body': {
      'Html': {
      'Charset': CHARSET,
      'Data': BODY_HTML,
      },
      'Text': {
      'Charset': CHARSET,
      'Data': BODY_TEXT,
      },
      },
      'Subject': {
      'Charset': CHARSET,
      'Data': SUBJECT,
      },
      },
      Source=SENDER,
      # If you are not using a configuration set, comment or delete the
      # following line
      # ConfigurationSetName=CONFIGURATION_SET,
      )
      # Display an error if something goes wrong.
      except Exception as e:
      print(e.response['Error']['Message'])
      else:
      print("Email sent! Message ID:"),
      print(response['MessageId'])


      The Email Result:



      enter image description here



      Sources & Further Help/Examples:




      • Python to PHP: Converting Python Code to PHP


      • AWS Boto3 Python 3.6 SES Example: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-python.html


      • Basic HTML CSS For Tables: https://www.w3schools.com/css/css_table.asp


      • More AWS SES Help: https://aws.amazon.com/ses/getting-started/



      Note:



      To run this example easily I recommend setting up a quick Cloud9 IDE in AWS, installing Python 3 on it, copy and paste my code into it, then click run. If your Cloud9 has the proper roles and permissions to use SES then it should work. Also note that Cloud9 is just running on top of an EC2-Instance so you can SSH into it (directly from the Management Console on your browser which is nice) and run something like "sudo yum install python-3.6" and manually run the code using "sudo touch code_example.py", "sudo chmod 755 code_example.py", "sudo vi code_example.py", then hit the "i" key which stands for insert, then right click and for my SSH client that pastes the code I had copied onto my clipboard into the SSH's text editor for VI, then click "ESC" to get out of insert mode, then click ":wq" and click enter which stands for "write" and then "quit", then to run it do "python3 code_example.py". If you successfully installed Python it should work. But like I said it's easier to just use Cloud9, open the IDE for Cloud9, create a new Python file, paste the code in, then run it as Python 3 there's a button that does it just like any normal IDE.



      enter image description here






      share|improve this answer




























        0












        0








        0







        My example here is using the Boto3 library for Python 3 but I think it could still translate into this PHP question mainly because the core of the problem is not PHP specific but rather the HTML inside your HTML_BODY field for SES and that is language agnostic so my example here should help.



        This code successfully sends to my email address, formatted exactly how it appears in the example on W3 Schools here



        HTML Example:



        <!DOCTYPE html>
        <html>
        <head>
        <style>
        table {
        border-collapse: collapse;
        width: 100%;
        }

        th, td {
        text-align: left;
        padding: 8px;
        }

        tr:nth-child(even){background-color: #f2f2f2}
        </style>
        </head>
        <body>

        <h2>Responsive Table</h2>
        <p>A responsive table will display a horizontal scroll bar if the screen is too
        small to display the full content. Resize the browser window to see the effect:</p>
        <p>To create a responsive table, add a container element (like div) with <strong>overflow-x:auto</strong> around the table element:</p>

        <div style="overflow-x:auto;">
        <table>
        <tr>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        </tr>
        <tr>
        <td>Jill</td>
        <td>Smith</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        </tr>
        <tr>
        <td>Eve</td>
        <td>Jackson</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        </tr>
        <tr>
        <td>Adam</td>
        <td>Johnson</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        </tr>
        </table>
        </div>

        </body>
        </html>


        AWS SES Example Using The Above HTML:



        #Your Imports go here
        import boto3

        # Replace sender@example.com with your "From" address.
        # This address must be verified with Amazon SES.
        SENDER = "the_email_address_of_who_is_sending_this_email_out@gmail.com"

        # Replace recipient@example.com with a "To" address. If your account
        # is still in the sandbox, this address must be verified.
        RECIPIENT = "the_email_address_of_who_will_be_receiving_this_email@gmail.com"

        # Specify a configuration set. If you do not want to use a configuration
        # set, comment the following variable, and the
        # ConfigurationSetName=CONFIGURATION_SET argument below.
        # CONFIGURATION_SET = "ConfigSet"

        # If necessary, replace us-west-2 with the AWS Region you're using for Amazon SES.
        AWS_REGION = "us-east-1"

        # The subject line for the email.
        SUBJECT = "ARL Data Lake"

        # The email body for recipients with non-HTML email clients.
        # BODY_TEXT = ("Amazon SES Test (Python)rn"
        # "This email was sent with Amazon SES using the "
        # "AWS SDK for Python (Boto)."
        # )
        BODY_TEXT = str(records)

        # The HTML body of the email.

        BODY_HTML = """<!DOCTYPE html>
        <html>
        <head>
        <style>
        table {
        border-collapse: collapse;
        width: 100%;
        }

        th, td {
        text-align: left;
        padding: 8px;
        }

        tr:nth-child(even){background-color: #f2f2f2}
        </style>
        </head>
        <body>

        <h2>Responsive Table</h2>
        <p>A responsive table will display a horizontal scroll bar if the screen is too
        small to display the full content. Resize the browser window to see the effect:</p>
        <p>To create a responsive table, add a container element (like div) with <strong>overflow-x:auto</strong> around the table element:</p>

        <div style="overflow-x:auto;">
        <table>
        <tr>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        </tr>
        <tr>
        <td>Jill</td>
        <td>Smith</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        </tr>
        <tr>
        <td>Eve</td>
        <td>Jackson</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        </tr>
        <tr>
        <td>Adam</td>
        <td>Johnson</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        </tr>
        </table>
        </div>

        </body>
        </html>"""

        # The character encoding for the email.
        CHARSET = "UTF-8"

        # Create a new SES resource and specify a region.
        client = boto3.client('ses', region_name=AWS_REGION)

        # Try to send the email.
        try:
        # Provide the contents of the email.
        response = client.send_email(
        Destination={
        'ToAddresses': [
        RECIPIENT,
        ],
        },
        Message={
        'Body': {
        'Html': {
        'Charset': CHARSET,
        'Data': BODY_HTML,
        },
        'Text': {
        'Charset': CHARSET,
        'Data': BODY_TEXT,
        },
        },
        'Subject': {
        'Charset': CHARSET,
        'Data': SUBJECT,
        },
        },
        Source=SENDER,
        # If you are not using a configuration set, comment or delete the
        # following line
        # ConfigurationSetName=CONFIGURATION_SET,
        )
        # Display an error if something goes wrong.
        except Exception as e:
        print(e.response['Error']['Message'])
        else:
        print("Email sent! Message ID:"),
        print(response['MessageId'])


        The Email Result:



        enter image description here



        Sources & Further Help/Examples:




        • Python to PHP: Converting Python Code to PHP


        • AWS Boto3 Python 3.6 SES Example: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-python.html


        • Basic HTML CSS For Tables: https://www.w3schools.com/css/css_table.asp


        • More AWS SES Help: https://aws.amazon.com/ses/getting-started/



        Note:



        To run this example easily I recommend setting up a quick Cloud9 IDE in AWS, installing Python 3 on it, copy and paste my code into it, then click run. If your Cloud9 has the proper roles and permissions to use SES then it should work. Also note that Cloud9 is just running on top of an EC2-Instance so you can SSH into it (directly from the Management Console on your browser which is nice) and run something like "sudo yum install python-3.6" and manually run the code using "sudo touch code_example.py", "sudo chmod 755 code_example.py", "sudo vi code_example.py", then hit the "i" key which stands for insert, then right click and for my SSH client that pastes the code I had copied onto my clipboard into the SSH's text editor for VI, then click "ESC" to get out of insert mode, then click ":wq" and click enter which stands for "write" and then "quit", then to run it do "python3 code_example.py". If you successfully installed Python it should work. But like I said it's easier to just use Cloud9, open the IDE for Cloud9, create a new Python file, paste the code in, then run it as Python 3 there's a button that does it just like any normal IDE.



        enter image description here






        share|improve this answer















        My example here is using the Boto3 library for Python 3 but I think it could still translate into this PHP question mainly because the core of the problem is not PHP specific but rather the HTML inside your HTML_BODY field for SES and that is language agnostic so my example here should help.



        This code successfully sends to my email address, formatted exactly how it appears in the example on W3 Schools here



        HTML Example:



        <!DOCTYPE html>
        <html>
        <head>
        <style>
        table {
        border-collapse: collapse;
        width: 100%;
        }

        th, td {
        text-align: left;
        padding: 8px;
        }

        tr:nth-child(even){background-color: #f2f2f2}
        </style>
        </head>
        <body>

        <h2>Responsive Table</h2>
        <p>A responsive table will display a horizontal scroll bar if the screen is too
        small to display the full content. Resize the browser window to see the effect:</p>
        <p>To create a responsive table, add a container element (like div) with <strong>overflow-x:auto</strong> around the table element:</p>

        <div style="overflow-x:auto;">
        <table>
        <tr>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        </tr>
        <tr>
        <td>Jill</td>
        <td>Smith</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        </tr>
        <tr>
        <td>Eve</td>
        <td>Jackson</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        </tr>
        <tr>
        <td>Adam</td>
        <td>Johnson</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        </tr>
        </table>
        </div>

        </body>
        </html>


        AWS SES Example Using The Above HTML:



        #Your Imports go here
        import boto3

        # Replace sender@example.com with your "From" address.
        # This address must be verified with Amazon SES.
        SENDER = "the_email_address_of_who_is_sending_this_email_out@gmail.com"

        # Replace recipient@example.com with a "To" address. If your account
        # is still in the sandbox, this address must be verified.
        RECIPIENT = "the_email_address_of_who_will_be_receiving_this_email@gmail.com"

        # Specify a configuration set. If you do not want to use a configuration
        # set, comment the following variable, and the
        # ConfigurationSetName=CONFIGURATION_SET argument below.
        # CONFIGURATION_SET = "ConfigSet"

        # If necessary, replace us-west-2 with the AWS Region you're using for Amazon SES.
        AWS_REGION = "us-east-1"

        # The subject line for the email.
        SUBJECT = "ARL Data Lake"

        # The email body for recipients with non-HTML email clients.
        # BODY_TEXT = ("Amazon SES Test (Python)rn"
        # "This email was sent with Amazon SES using the "
        # "AWS SDK for Python (Boto)."
        # )
        BODY_TEXT = str(records)

        # The HTML body of the email.

        BODY_HTML = """<!DOCTYPE html>
        <html>
        <head>
        <style>
        table {
        border-collapse: collapse;
        width: 100%;
        }

        th, td {
        text-align: left;
        padding: 8px;
        }

        tr:nth-child(even){background-color: #f2f2f2}
        </style>
        </head>
        <body>

        <h2>Responsive Table</h2>
        <p>A responsive table will display a horizontal scroll bar if the screen is too
        small to display the full content. Resize the browser window to see the effect:</p>
        <p>To create a responsive table, add a container element (like div) with <strong>overflow-x:auto</strong> around the table element:</p>

        <div style="overflow-x:auto;">
        <table>
        <tr>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        <th>Points</th>
        </tr>
        <tr>
        <td>Jill</td>
        <td>Smith</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        <td>50</td>
        </tr>
        <tr>
        <td>Eve</td>
        <td>Jackson</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        <td>94</td>
        </tr>
        <tr>
        <td>Adam</td>
        <td>Johnson</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        <td>67</td>
        </tr>
        </table>
        </div>

        </body>
        </html>"""

        # The character encoding for the email.
        CHARSET = "UTF-8"

        # Create a new SES resource and specify a region.
        client = boto3.client('ses', region_name=AWS_REGION)

        # Try to send the email.
        try:
        # Provide the contents of the email.
        response = client.send_email(
        Destination={
        'ToAddresses': [
        RECIPIENT,
        ],
        },
        Message={
        'Body': {
        'Html': {
        'Charset': CHARSET,
        'Data': BODY_HTML,
        },
        'Text': {
        'Charset': CHARSET,
        'Data': BODY_TEXT,
        },
        },
        'Subject': {
        'Charset': CHARSET,
        'Data': SUBJECT,
        },
        },
        Source=SENDER,
        # If you are not using a configuration set, comment or delete the
        # following line
        # ConfigurationSetName=CONFIGURATION_SET,
        )
        # Display an error if something goes wrong.
        except Exception as e:
        print(e.response['Error']['Message'])
        else:
        print("Email sent! Message ID:"),
        print(response['MessageId'])


        The Email Result:



        enter image description here



        Sources & Further Help/Examples:




        • Python to PHP: Converting Python Code to PHP


        • AWS Boto3 Python 3.6 SES Example: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-python.html


        • Basic HTML CSS For Tables: https://www.w3schools.com/css/css_table.asp


        • More AWS SES Help: https://aws.amazon.com/ses/getting-started/



        Note:



        To run this example easily I recommend setting up a quick Cloud9 IDE in AWS, installing Python 3 on it, copy and paste my code into it, then click run. If your Cloud9 has the proper roles and permissions to use SES then it should work. Also note that Cloud9 is just running on top of an EC2-Instance so you can SSH into it (directly from the Management Console on your browser which is nice) and run something like "sudo yum install python-3.6" and manually run the code using "sudo touch code_example.py", "sudo chmod 755 code_example.py", "sudo vi code_example.py", then hit the "i" key which stands for insert, then right click and for my SSH client that pastes the code I had copied onto my clipboard into the SSH's text editor for VI, then click "ESC" to get out of insert mode, then click ":wq" and click enter which stands for "write" and then "quit", then to run it do "python3 code_example.py". If you successfully installed Python it should work. But like I said it's easier to just use Cloud9, open the IDE for Cloud9, create a new Python file, paste the code in, then run it as Python 3 there's a button that does it just like any normal IDE.



        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 27 '18 at 21:00

























        answered Nov 27 '18 at 20:39









        Kyle BridenstineKyle Bridenstine

        1,28321644




        1,28321644






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18952620%2fcss-not-working-in-email-sending-using-aws%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)