Jump to content

[SOLVED] HTML Email - Portable solution?


tmallen

Recommended Posts

I need to send HTML email using PHP, and the solution needs to be very portable (no need for server installations using PEAR, which as far as I know puts the mime_mail extension out of the question). How can I do this?

 

So, anyone know of portable, fairly easy to use HTML email solutions?

Link to comment
https://forums.phpfreaks.com/topic/75686-solved-html-email-portable-solution/
Share on other sites

Quoted from PHP.net @ http://us.php.net/function.mail

 

Example 1127. Sending HTML email

It is also possible to send HTML email with mail().

<?php
// multiple recipients
$to  = '[email protected]' . ', '; // note the comma
$to .= '[email protected]';

// 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, 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";

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?> 

In a way this works but the "Additional Headers" line is no good. Here's what I see in the result email. The code follows.

Fake Name From: Sitename Cc: [email protected] Bcc: [email protected]

// Additional headers
$headers .= 'Fake Name <[email protected]>' . "\r\n";
$headers .= 'From: Sitename' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

Note that I've censored the names and emails for privacy. The additional headers didn't successfully affect the From, To, Cc, or Bcc successfully.

 

The HTML mail does work very well though.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.