By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,361 Members | 1,955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,361 IT Pros & Developers. It's quick & easy.

sending email with php

P: 54
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $headers = "Content-type: text/html; charset=iso-8859-1";
  4. $to="myemailaddress";
  5. $subject="Email Newsletter";
  6.  
  7. $message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  8. <html xmlns="http://www.w3.org/1999/xhtml">
  9. <head>
  10. <title>Email Newsletter</title>
  11. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  12. <meta name="robots" content="noindex, nofollow" />
  13. <link rel="stylesheet" type="text/css" href="style.css" />
  14. </head>
  15.  
  16. <body>
  17. <div id="wrapper">
  18.     <div id="topmenu">
  19.     </div>
  20.     <div id="content">
  21.         <div class="leftcolumn">
  22.         </div>
  23.         <div class="rightcolumn">
  24.         </div>
  25.     </div>
  26.     <div id="footer">
  27.     </div>
  28. </div>
  29. </body>
  30. </html>';
  31.  
  32. if(! mail($to, $subject, $message, $headers)){
  33.     echo "There was an error is sending the email";
  34.     }
  35.     else{
  36.     echo "The email has been sent";
  37.     }
  38. ?>
hi

my question is about send an email with php like a newsletter, when we read a newsletter email its similar to a webpage which contains content, images, css and other elements

i created a static webpage initially with html css and images folder after creating the page i wanted to test to see how it would look if i were to send this as an email like a newsletter.

so i have created a php file with
Expand|Select|Wrap|Line Numbers
  1. $headers = "Content-type: text/html; charset=iso-8859-1";
  2. $to="myemailaddress";
  3. $subject="Email Newsletter";
and
$message as mentioned above has the entire html code as i used it in my static html page
i also copied the style.css in the server and created images folder and copied all the images i used in my static page to the server.

i created a separate folder in my webserver called newsletter and copied the php file, css file and images folder with the images i used

when i accessed the index.php as http://website.com/emailnewsletter i am getting a message that The email has been sent and i am getting the email

however my question is when i open this email the styles and images are not being applied and i see only the text in the static page i created.


can someone let me know how i can fix this so that when i open the email it would look like the static page i created with all the styles applies and images displayed

is this only possible by using specialized email softwares or can it be done by php as well with the logic used.


any help will be appreciated.

thanks
Dec 23 '09 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
try to use absolute URLs (like http://example.org/style.css)
Dec 24 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.