Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

html formatted email

Status
Not open for further replies.

MasterKaos

Programmer
Joined
Jan 17, 2004
Messages
107
Location
GB
I'm using the mail() function to send email, was wonderring what i have to do to send it in html? I'm assuming i need to send some sort of headers that identify the message as html?

Also, at the moment html is overkill, because i'm just using it to for new lines. If i'm not using html, how would i put a newline character in? I mean the message body is being pasted together from a few strings, i would like to put a new line between each string.

Hope the above makes sense, i'm pretty tired...

Thanks!

----------------------------------------------------------------------------
The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.
 
Umm, ok so does this mean i have to add on a library to PHP to send html mail? is it not possible to send html email using the standard modules included in php?

----------------------------------------------------------------------------
The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.
 
yes, you can do it, but what the guys are telling you is there are some libraries to make your code easy to implement.

Anyway, take a look to example 4 of mail function in php.net:

Code:
<?php
/* recipients */
$to  = "mary@example.com" . ", " ; // note the comma
$to .= "kelly@example.com";

/* subject */
$subject = "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>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>
';

/* To send HTML mail, you can set the Content-type header. */
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

/* additional headers */
$headers .= "To: Mary <mary@example.com>, Kelly <kelly@example.com>\r\n";
$headers .= "From: Birthday Reminder <birthday@example.com>\r\n";
$headers .= "Cc: birthdayarchive@example.com\r\n";
$headers .= "Bcc: birthdaycheck@example.com\r\n";

/* and now mail it */
mail($to, $subject, $message, $headers);
?>
 
take a look to $headers in the previous example.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top