php mail

CerIs

New member
Jun 9, 2007
372
7
0
Hi, im having problems sending html emails with php (yes I know this is supposed to be easy). So using the code below the email sends but when I view the mail it has the html as plain text, im assuming this is mime-type stuff?

PHP:
<?php
 require_once "Mail.php";
 
 $from = "Them <testing@test.com>";
 $to = "me@yahoo.com";
 $subject = "Hi!";
 $body = "<table border='0' cellspacing='0' cellpadding='0' width='666' align='center'>
    <tbody>
        <tr>
            <td bgcolor='#b4afb4'>Hello world</td>
        </tr>
    </tbody>
</table>";
 
 $host = "mail.mymailserver.com";
 $username = "testing@test.com";
 $password = "wicked";
 
 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'auth' => true,
     'username' => $username,
     'password' => $password));
 
$headers["MIME-Version"] = "MIME-Version: 1.0" . "\r\n"; 
$headers["Content-Type"] = "Content-type:text/html;charset=iso-8859-1" . "\r\n"; 
 
 $mail = $smtp->send($to, $headers, $body);
 
 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Message successfully sent!</p>");
  }
 ?>
 


yeah I put html,head,body in but it still displays as text, must be something else
 
It IS EASY to blast out emails with plain php.


This works by itself. Just swap in email to send to and your noreply domain name. Put your html outside the php tags, and buffer it into an object you send as the message.
Code:
<?php
                    $email = 'youremailtotestorgetfromform';             
                    $to      = $email; //Send email to our user
                    $subject = 'Signup | Verification'; //// SUBJECT LINE 
                             
                    $headers = 'From:noreply@mydomain.com' . "\r\n";
                    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                    ob_start();  //Start Buffering
?>

<html>  //add your doctype and metadata for whatever html you want to make.
<head>
</head><body>  
<h2>Check out this heading!</h2>
<p>This is something with <b>HTML</b> formatting.</p> 
</body></html>


<?php
$message = ob_get_clean();  //Close buffering
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
:cool-smiley-008: