Connecting Tech Pros Worldwide Forums | Help | Site Map

Send HTML mail with PEAR

Newbie
 
Join Date: Aug 2007
Posts: 15
#1: Oct 6 '07
Hi!

Im trying to send a html mail through PEAR but what I get in mail is blank email.

Below is my code

[PHP]
require_once "Mail.php";
require_once "Mail\mime.php";

$html = @file_get_contents(GetEmailBody());

$message = new Mail_mime();
$message->setHTMLBody($html);
$body = $message->get();
$from = "abc@sample.com";
$namefrom = "Sample";
$to ="johnsmith@sample.com";
$nameto = "John Smith";
$subject = "Sample";

$host = "mail.sample.com";
$username = "sample@sample.com";
$password = "sample";

$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>");
}
[/PHP]

Thank you
Daniel Nawaz

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Oct 6 '07

re: Send HTML mail with PEAR


Heya, Daniel.

What does GetEmailBody() return?
Newbie
 
Join Date: Aug 2007
Posts: 15
#3: Oct 6 '07

re: Send HTML mail with PEAR


returns a string containing HTML tags and data....

when i simply do this
Expand|Select|Wrap|Line Numbers
  1. $body = GetEmailBody();
instead of setting Mime_mail

I'm mailed with HTML source text. Not compiled page.
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#4: Oct 6 '07

re: Send HTML mail with PEAR


Heya, daniyalnawaz.

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]

Try removing the file_get_contents() around GetEmailBody().
Newbie
 
Join Date: Aug 2007
Posts: 15
#5: Oct 6 '07

re: Send HTML mail with PEAR


Hi!

Now im again getting HTML text in the mail.
Newbie
 
Join Date: Aug 2007
Posts: 15
#6: Oct 6 '07

re: Send HTML mail with PEAR


and on thing more...

i change the $html to

[PHP]$html = "<table width='100%' border='1'><tr><td>HELLO</td></tr><table>";[/PHP]

and what i recieve in email is

[HTML]<table width=3D'100%' border=3D'1'><tr><td>HELLO</td></tr><table>[/HTML]

what 3Ds are doing in it?
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#7: Oct 6 '07

re: Send HTML mail with PEAR


Heya, Daniyalnawaz.

This is expected behavior.

Have a look at this page.
Newbie
 
Join Date: Aug 2007
Posts: 15
#8: Oct 6 '07

re: Send HTML mail with PEAR


Ok what should I do? Am I missing something? Any other way i should use?

Is my HTML incorrect?

[PHP]$html = "<html><body><table width='100' border='1'><tr><td>HELLO</td></tr></table></body></html>";[/PHP]
Reply