Jump to content

Recommended Posts

<?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?

Link to comment
https://forums.phpfreaks.com/topic/64811-html-emails/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/64811-html-emails/#findComment-323337
Share on other sites

<?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!

Link to comment
https://forums.phpfreaks.com/topic/64811-html-emails/#findComment-323391
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.