Space Cowboy Posted August 14, 2007 Share Posted August 14, 2007 <?php //--SETS UP THE EMAIL LAYOUT WITH VARIABLES IN PLACE $administrator="$email"; $subject="test mails"; $message.="$textarea\n"; //--SENDS THE EMAIL mail($administrator,$subject,$message,"From:gareth@humberep.co.uk"); ?> Hello, this is the code im using to send out an email (the variable $textarea" comes from a form (text area) just submitted). The emails are sending out, however if I send out html, the actual code shows up in the email rather than the visual style the HTML should render. How do I change this? Quote Link to comment https://forums.phpfreaks.com/topic/64811-html-emails/ Share on other sites More sharing options...
denechtew Posted August 14, 2007 Share Posted August 14, 2007 I can be wrong cause I'm learning php, but maybe it is: mail($administrator,$subject,$message.,"From:gareth@humberep.co.uk"); ?> cause you said in $message. Quote Link to comment https://forums.phpfreaks.com/topic/64811-html-emails/#findComment-323296 Share on other sites More sharing options...
NArc0t1c Posted August 14, 2007 Share Posted August 14, 2007 You need the MIME header. http://www.zend.com/zend/trick/html-email.php Quote Link to comment https://forums.phpfreaks.com/topic/64811-html-emails/#findComment-323303 Share on other sites More sharing options...
Space Cowboy Posted August 14, 2007 Author Share Posted August 14, 2007 thanks, but I dont understand where to insert the headers. Ive tried copying and pasting the script on the page you gave but it just comes up with errors. Do the headers need to be sent within the html part of the email or they are just set within the script? Quote Link to comment https://forums.phpfreaks.com/topic/64811-html-emails/#findComment-323337 Share on other sites More sharing options...
Space Cowboy Posted August 14, 2007 Author Share Posted August 14, 2007 <?php //add From: header $headers = "From: newsletter@domain.co.uk\r\n"; //specify MIME version 1.0 $headers .= "MIME-Version: 1.0\r\n"; //unique boundary $boundary = uniqid("HTMLDEMO"); //tell e-mail client this e-mail contains//alternate versions $headers .= "Content-Type: multipart/alternative" . "; boundary = $boundary\r\n\r\n"; //message to people with clients who don't understand MIME $headers .= "This is a MIME encoded message.\r\n\r\n"; //plain text version of message $headers .= "--$boundary\r\n" . "Content-Type: text/plain; charset=ISO-8859-1\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode("This is the plain text version!")); //HTML version of message $headers .= "--$boundary\r\n" . "Content-Type: text/html; charset=ISO-8859-1\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode("$abstract")); //send message mail("$email", "An HTML Message", "", $headers); ?> OK, ive adapted this code and I think im getting somewhere. The email is being recieved in HTML, things like the bold/strong tag and H1/h2 tags are being picked up, but its stripping all style. If I send something with a table like this: <table width="680" border="4" align="center" cellpadding="0" cellspacing="0" bordercolor="#257690" bgcolor="#257690"> its being stripped and when recieved its coming out as just <table> arrrghhhhhhhhhhhhh! Quote Link to comment https://forums.phpfreaks.com/topic/64811-html-emails/#findComment-323391 Share on other sites More sharing options...
NArc0t1c Posted August 14, 2007 Share Posted August 14, 2007 Try making it W3 compliant. Try this: <table width="680" style="border:4px;bordercolor:#257690;bgcolor:#257690;align:center;cellpadding:0;cellspacing:0"> Quote Link to comment https://forums.phpfreaks.com/topic/64811-html-emails/#findComment-323456 Share on other sites More sharing options...
Space Cowboy Posted August 14, 2007 Author Share Posted August 14, 2007 for some reason that isnt sending it out at all!!! besides which, I cant rely on whats being sent being W3 complient...and many HTML emails are sent out without being complient. Quote Link to comment https://forums.phpfreaks.com/topic/64811-html-emails/#findComment-323488 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.