sending email with php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • runway27
    Banned
    New Member
    • Sep 2007
    • 54

    sending email with php

    Code:
    <?php
    
    $headers = "Content-type: text/html; charset=iso-8859-1";
    $to="myemailaddress";
    $subject="Email Newsletter";
    
    $message = '<!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>
    <title>Email Newsletter</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="robots" content="noindex, nofollow" />
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    
    <body>
    <div id="wrapper">
    	<div id="topmenu">
    	</div>
    	<div id="content">
    		<div class="leftcolumn">
    		</div>
    		<div class="rightcolumn">
    		</div>
    	</div>
    	<div id="footer">
    	</div>
    </div>
    </body>
    </html>';
    
    if(! mail($to, $subject, $message, $headers)){
    	echo "There was an error is sending the email";
    	}
    	else{
    	echo "The email has been sent";
    	}
    ?>
    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
    Code:
    $headers = "Content-type: text/html; charset=iso-8859-1";
    $to="myemailaddress";
    $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
    Last edited by Atli; Dec 23 '09, 10:27 PM. Reason: Added [code] tags.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    try to use absolute URLs (like http://example.org/style.css)

    Comment

    Working...