I have a code which emails in regular non-html format. How can I change to HTML?
Printable View
I have a code which emails in regular non-html format. How can I change to HTML?
add a Content-type header:
an example of doing this exists on the mail() function documentation.Code:Content-type: text/html;
PHP_EOL places an end-of-line character, which differs depending on the operating system (\r\n, or \n). this is a line break.
Ok I looked at the site and made some changes. It was working at first but now I'm not receiving any email even though when I print out the result in this page there seems to be no problem:
edited this post:
Ok. I tried an example. I removed my previous attachment and attached the following:
I've been looking at:
I want to use css, if possible in my newsletters to email. But I can't find any info on this.PHP Code:// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//$headers .= 'Content-type: text/css; charset=iso-8859-1' . "\r\n";
$headers .= 'Content-type: text/css;' . "\r\n";
I'm not going to download your attachment. just copy and paste the code into your post.
PHP Code:<?php
// multiple recipients
$to = '[email protected]'.', '; // note the comma
$to .= '[email protected]';
$from = "[email protected]";
// subject
$subject = 'Another Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td style=\"font-weight: bold;\">Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';//<font size="3" color="red"></font>
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//$headers .= 'Content-type: text/css; charset=iso-8859-1' . "\r\n";
$headers .= 'Content-type: text/css;' . "\r\n";
// Additional headers
//$headers .= 'To: ' . $to . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
//$headers .= 'Cc: ' . "\r\n";
//$headers .= 'Bcc: ' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
<!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>
<div style="text-align: center;">
<b>Thank you <br /><?php
echo "From: " . $_REQUEST['youremail']."<br />\n";
echo "Emails sent to: ".$_REQUEST['theiremail']."<br />\n";
echo "Subject: ".$_REQUEST['subject']."<br />\n";
echo "Passage: ".$_REQUEST['passage']."<br />\n";
?></b><br />
Your message has been sent
<p><a href="<?php echo $baseURL; ?>">Click here to continue</a></p>
</div>
</body>
</html>
you can't set your content-type to "text/css" -- that would set the content type to that of a CSS file, which you are not sending. use the header I showed you in an earlier post.
if it isn't working, try using PEAR::Mail with PEAR::Mail_Mime instead.
what do you mean how? you use CSS just like you would always use CSS. it's not like the way CSS works is changed when used in email versus on the web. some email clients don't properly support everything though.
I don't think Hotmail is supporting. I'm not getting the emails i send when there's css in it. ANd I think some tags aren't supported either. <b> seems ok though.
And it's going in my junk folder and at times it won't even open.
http://www.gbgrafix.com/thewheelofgo...ts/emailex.php
I created a form with a get method and a textarea. Try it out for yourself.
Possibly the email address you send 'From' does not belong to the SMTP server and thus is not verifiable.
Spam filters will consider this junk.
What you might want to do is use a no-reply address belonging to your domain.
So $from = "[email protected]"; would be $from = "[email protected]";
Try it.
Also, can you post the source of one of those CSS using emails?
Ok I added $from="[email protected]" but no change.
It seems that emails accept some css attributes like color, weight, font-style but reject z-index, position...
is there a function which informs you that the email is sent or not? I only find out if I receive it. And sometimes it takes hours.
the mail() function returns a boolean value of whether or not the mail was sent successfully. this doesn't mean that your mail wasn't picked up in a spam filter. server load will have a lot to do with when mail is sent, too. I'd recommend using a more appropriate way of sending mail (rather than sendmail with PHP's mail() function) -- SMTP. you can use PEAR::Mail or other mailing libraries for this. this would also be a better better for sending complex mail with HTML or attachments.
There is no spec on HTML and CSS in emails and some people (like me) dislike receiving them. I suggest sticking to plain text. At the very least, you need to provide a plain text alternative, which can be done with multipart encoding.
Also, headers are supposed to be separated by \r\n regardless of platform, but in practice I think this varies and \n is probably safer.