0

I have a php script that i use to send mails to lists of emails in my database, but the mail appears in text form only. Now i want my subscribers to get their mails in HTML format.
Please help me out.

2
Contributors
3
Replies
8
Views
5 Years
Discussion Span
Last Post by cereal
0

Thanks, I tried it but i still get the mail in full-text format but i want my mails to appear in HTML format. Can u help out, this is the code i used.

<?php
require_once "Mail.php";
error_reporting(E_ALL - (E_NOTICE + E_WARNING));

 $form_string= <<<EOFORM
     <HTML>
     <HEAD>
     <TITLE>Send a Newsletter</TITLE>
     </HEAD>
     <BODY>
   	<h2>Send  Newsletter</h2>
    <form method="POST" action="$_SERVER[PHP_SELF]">
    <P><strong>Subject:</strong><br>
    <input type="text" name="subject" size=30></p>
    <P><strong>Mail Body:</strong><br>
    <textarea name="message" cols=50 rows=10 wrap=virtual></textarea>
    <input type="hidden" name="op" value="send">
    <p><input type="submit" name="submit" value="Send Now"></p>
    </FORM>
</BODY> </HTML>
EOFORM;
$from = "info@seapmicrofinance.org";
$subject = stripslashes($_POST['subject']);
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table bgcolor=#EEEEEE>
    <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>
';

$username = "USERNAME";
$password = "PASSWORD";
$host = "smtp.seapmicrofinance.org";  // replace this with your domain's webmail address, for example "smtp.YourDomain.com"

  if ($_POST[op] != "send") {
     //haven't seen the form, so show it
	echo $form_string;

 } else if ($_POST[op] == "send") {
     //want to send form, so check for required fields
     if (($_POST[subject] =="") || ($_POST[message] == "")) {
        header("Location: mailing_script2.php");
        exit;
    }

    //connect to database
    $conn = mysql_connect("XpertProCombined", "gbenga", "micrBANK1@")
         or die(mysql_error());
    mysql_select_db("seap?users",$conn) or die('Connection Failed!');

    //get emails from subscribers list
    $sql = "select user_email from users";
    $result = mysql_query($sql,$conn) or die(mysql_error());

    //create a From: mailheader
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= "From: SEAP Microfinance <info@seapmicrofinance.org>";

    //loop through results and send mail
    while ($row = mysql_fetch_array($result)) {
        set_time_limit(0);
        $email = $row['user_email'];
		$headers = array ('From' => $from, 'To' => $email, 'Subject' => $subject);
	    $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
		
		$mail = $smtp->send($email, $headers, $message);
		 echo "newsletter sent to: $email<br>";
    }
	if (PEAR::isError($mail)) 
		{
  			echo("<p>" . $mail->getMessage() . "</p>");
		}

}
 }
 ?>

Edited by peter_budo: Added code tags

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.