Jump to content

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  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@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, 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 <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";

// 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: fakemail@email.com Bcc: fakemail2@email.com

// Additional headers
$headers .= 'Fake Name <myfakemail@email.com>' . "\r\n";
$headers .= 'From: Sitename' . "\r\n";
$headers .= 'Cc: fakemail@email.com' . "\r\n";
$headers .= 'Bcc: fakemail2@email.com' . "\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.

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.