Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php mail using pear

Status
Not open for further replies.

electricphp

Programmer
Feb 20, 2008
71
US
I am trying to set the format of this email as html instead of plain text, but I can't figure out how to do it. Maybe you guys can help:

Code:
require_once "../pearmail/Mail.php";

$from = "aaaa <info@aaaaa.com>";
$to =  "aaaa@daaaa.com"; ;
$subject = "aaaaa.com, a message from ".$_POST['name'];    
$body = Hello ". $_POST['fname'].", ".$_POST['name']." wants you to check out the following webpage:<a href='aa.com'>".$_POST['pg']."</a>";
$host = "localhost";
$username = "info@aaaa.com";
$password = "aaaaaa";

$headers = array ('From' => $from,
  'To' => $to,
  '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>");
 }
}
 
i suggest you use phpmailer instead.

if you want to use pear::mail you have to set the headers to use the right MIME content type.
 
right, that's what I'm asking, how to set the headers to use the right MIME content type, meaning an html format email.

I'm already using pear for other forms on he site, so I wouldlike to stick with it.
 
you are adding significant hassle by not using phpmailer. and if you must you could always rewrite the phpmailer class to use the pear framework. it would only be the errorhandling that changes.

you set the headers simply by adding the right mime type as a string in the headers argument.

in this case the string would be something like

Code:
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
 
thanks, in fact I got it to work. I thought putting would not work as a hyperlink, i assumed you would need to put in the a href in front of it and when i did that it printed out <a href="">blah</a> instead of printing a link.
 
ah. email readers will often turn unqualified url's into links. but this is a function of the reader rather than the mail class.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top