Jump to content

php mail in html mail


bradkenyon

Recommended Posts

I am using a script, that uses a pear library, I use to use the html mime mail library which did a great job w/ html email

 

I am wondering how I could set this email msg to be in html.

<?php
require_once "Mail.php";

$from = "[email protected]";
$to = "receiver@ domain.edu";
$subject = "Hi!";
$body = "<p>Hi, How are you?</p>";

$host = "mail1.domain.edu";
$username = "user";
$password = "pass";

$headers = array ('From' => $from,
'To' => $to,
'X-From-Web' => $from,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if(PEAR::isError($mail))
{
echo("<p>" . $mail->getMessage() . "</p>");
}
else
{
echo("<p>Message successfully sent!</p>");
}
?>

 

The email msg I receive, has the <p></p> tags in it.

 

Link to comment
https://forums.phpfreaks.com/topic/124510-php-mail-in-html-mail/
Share on other sites

I am using a script, that uses a pear library, I use to use the html mime mail library which did a great job w/ html email

 

I am wondering how I could set this email msg to be in html.

<?php
require_once "Mail.php";

$from = "[email protected]";
$to = "receiver@ domain.edu";
$subject = "Hi!";
$body = "<p>Hi, How are you?</p>";

$host = "mail1.domain.edu";
$username = "user";
$password = "pass";

$headers = array ('From' => $from,
'To' => $to,
'X-From-Web' => $from,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if(PEAR::isError($mail))
{
echo("<p>" . $mail->getMessage() . "</p>");
}
else
{
echo("<p>Message successfully sent!</p>");
}
?>

 

The email msg I receive, has the <p></p> tags in it.

 

 

add this in your headers...

'MIME-Version: 1.0' . "\r\n";

'Content-type: text/html; charset=iso-8859-1' . "\r\n";

I recommend reading this: http://www.hudzilla.org/phpbook/read.php/15_5_3

 

You want to use this command

 

<?php

include('Mail.php');

include('Mail\mime.php');

 

$message = new Mail_mime();

$html = "<p>Hey</p>";

$message->setHTMLBody($html);

 

$body = $message->get();

$extraheaders = array("From"=>"[email protected]", "Subject"=>"My Subject 7");

$headers = $message->headers($extraheaders);

 

$mail = Mail::factory("mail");

$mail->send("[email protected]", $headers, $body);

 

?>

  • 5 weeks later...

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.