PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Problem with HTML mail ...

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Mail
View previous topic :: View next topic  
Author Message
Oliver77



Joined: 30 May 2009
Posts: 2

PostPosted: Sat May 30, 2009 8:57 am    Post subject: Problem with HTML mail ... Reply with quote

Hello,

I need your help ! I must send html mails with pear ... They are well sent, but their bodies are not in html ... The body is html code ...

I'm trying to solve this problem since a fews days without success ...

Thanks in advance for your help !

Here's my code :

Quote:

<?php
require_once( 'mime.php' );
require_once( 'Mail.php' );

$from = "MOI <[email protected]>";
$to = "TOI <[email protected]>";
$subject = "Essai Mail HTML avc PEAR";
$html = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /></head>
<body>Message en HTML</body>
</html>";

$host = "smtp.fai.fr";
$username = "monlogin";
$password = "monpwd";
$crlf = "\n";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);

$mime = new Mail_Mime($crlf);
$mime->setHTMLBody($html);
print_r($html);

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$smtp =& Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $headers, $body);
print_r($body);
?>
Back to top
View user's profile Send private message
Oliver77



Joined: 30 May 2009
Posts: 2

PostPosted: Sun May 31, 2009 6:30 pm    Post subject: [SOLVED] The solution to my problem ! Reply with quote

Hi,

So i finaly found my errors ...

Here's the code that works fine ... It may help someone ...

Code:
<?php
require_once( 'mime.php' );
require_once( 'Mail.php' );

$from = "MOI <[email protected]>";
$to = "TOI <[email protected]>";
$subject = "Essai Mail HTML avc PEAR";
$html = "<html>
<body>Message en HTML</body>
</html>";

$host = "smtp.fai.fr";
$username = "monlogin";
$password = "monpwd";
$crlf = "\n";
$hdrs = array ('From' => $from,
'To' => $to,
'Subject' => $subject);

$mime = new Mail_Mime($crlf);
$mime->setHTMLBody($html);
print_r($html);

$body = $mime->get();
$headers = $mime->headers($hdrs);

$smtp =& Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

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

?>
Back to top
View user's profile Send private message
boards



Joined: 26 Feb 2010
Posts: 1

PostPosted: Fri Feb 26, 2010 1:17 pm    Post subject: Reply with quote

we have a problem when sending the comments content via email to the users.y?
_________________
mrsa infection
mrsa infection
Back to top
View user's profile Send private message
roommonkey



Joined: 21 Apr 2010
Posts: 1

PostPosted: Wed Apr 21, 2010 5:59 pm    Post subject: Reply with quote

Hi there,

I think I'm having the same problem - have tried replicate the code, but it doesn't seem to displaying in HTML

The code I have is

Code:


   require_once "Mail.php";
   require_once 'Mail/mime.php';
   
   //$message = new Mail_mime();   

    //change this to your email.
    $to = '[email protected]';
    $from = "[email protected]";
    $subject = "website email message ";
   $host = "mail.example.co.uk";
   $username = "[email protected]";
   $password = "website";
   $crlf = "\n";
   
   //### SEND EMAIL TO USER  ###
   $html = " <p><font size=2 face=Arial color=#666666>The following enquiry has been posted on the example website:</font></p><table style=margin-left: 20px; font-family:Arial; font-size:11px border=0>";
   $html .=  "<tr><td nowrap style='padding-left:10px; padding-right:10px' bgcolor='#C0C0C0'>Name :</td><td class='value' bgcolor='#E4E4E4' style='padding-left: 10px; padding-right: 10px'>" . $_POST["Title"] . " " . $_POST["FirstName"] .  " " . $_POST["LastName"] . "</td></tr>";
   $html .=  "<tr><td nowrap colspan='2' height='5px' style='padding-left:10px; padding-right:10px' bgcolor='FFFFFF'></td></tr>";   
   $html .=  "<tr><td nowrap style='padding-left:10px; padding-right:10px' bgcolor='#C0C0C0'>Telephone :</td><td class='value' bgcolor='#E4E4E4' style='padding-left: 10px; padding-right: 10px'>" . $_POST["Telephone"] . "</td></tr>";
   $html .=  "<tr><td nowrap style='padding-left:10px; padding-right:10px' bgcolor='#C0C0C0'>Mobile :</td><td class='value' bgcolor='#E4E4E4' style='padding-left: 10px; padding-right: 10px'>" . $_POST["Mobile"] . "</td></tr>";
   $html .=  "<tr><td nowrap style='padding-left:10px; padding-right:10px' bgcolor='#C0C0C0'>E-mail address :</td><td class='value' bgcolor='#E4E4E4' style='padding-left: 10px; padding-right: 10px'>" . $_POST["EmailAddress"] . "</td></tr>";
   $html .=  "<tr><td nowrap colspan='2' height='5px' style='padding-left:10px; padding-right:10px' bgcolor='FFFFFF'></td></tr>";
   $html .=  "<tr><td nowrap style='padding-left:10px; padding-right:10px' bgcolor='#C0C0C0'>Address 1 :</td><td class='value' bgcolor='#E4E4E4' style='padding-left: 10px; padding-right: 10px'>" . $_POST["Address1"] . "</td></tr>";
   $html .=  "<tr><td nowrap style='padding-left:10px; padding-right:10px' bgcolor='#C0C0C0'>Address 2 :</td><td class='value' bgcolor='#E4E4E4' style='padding-left: 10px; padding-right: 10px'>" . $_POST["Address2"] . "</td></tr>";
   $html .=  "<tr><td nowrap style='padding-left:10px; padding-right:10px' bgcolor='#C0C0C0'>Address 3 :</td><td class='value' bgcolor='#E4E4E4' style='padding-left: 10px; padding-right: 10px'>" . $_POST["Address3"] . "</td></tr>";
   $html .=  "<tr><td nowrap colspan='2' height='5px' style='padding-left:10px; padding-right:10px' bgcolor='FFFFFF'></td></tr>";
   $html .=  "<tr><td nowrap style='padding-left:10px; padding-right:10px' bgcolor='#C0C0C0'>Enquiry :</td><td class='value' bgcolor='#E4E4E4' style='padding-left: 10px; padding-right: 10px'>" . $_POST["Enquiry"] . "</td></tr>";
   $html .=  "</table><br><p><font size='2' face='Arial' color='#666666'>Please do not reply to this email</font></p>";
      
   //####################################################
   
   $mime = new Mail_Mime($crlf);
   $mime->setHTMLBody($html);
   print_r($html);
   
   $body = $mime->get();

   //####################################################
   
   $headers = array (
   'From' => $from,
   'To' => $to,
   'Subject' => $subject,
   'EmailType' => $contentType);
   
   $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>");
   }




The result I get in the email browser (outlook) is below. Please note the '3D' and the extra '=' signs

Code:


<p><font size=3D2 face=3DArial color=3D#666666>The following enquiry has b= een posted on the Mutts and Mogs website:</font></p><table style=3Dmargin-l=
eft: 20px; font-family:Arial; font-size:11px border=3D0><tr><td nowrap styl= e=3D'padding-left:10px; padding-right:10px' bgcolor=3D'#C0C0C0'>Name :</td>= <td class=3D'value' bgcolor=3D'#E4E4E4' style=3D'padding-left: 10px; paddin=
g-right: 10px'>Mr Matt Povey</td></tr><tr><td nowrap colspan=3D'2' height= =3D'5px' style=3D'padding-left:10px; padding-right:10px' bgcolor=3D'FFFFFF'=
></td></tr><tr><td nowrap style=3D'padding-left:10px;
>padding-right:10px' b=




Any help would be appreciated, as I'm tearing my hair out!

Thanks
Back to top
View user's profile Send private message
brennanw



Joined: 20 May 2010
Posts: 8

PostPosted: Thu May 20, 2010 11:15 pm    Post subject: Reply with quote

roommonkey,

You are missing the <html><body></body></html> tags at the beginning and end.
Back to top
View user's profile Send private message
DKLeader



Joined: 12 Oct 2010
Posts: 1
Location: Ishoej, Denmark

PostPosted: Tue Oct 12, 2010 4:19 pm    Post subject: Reply with quote

Hi,

Followed the above trying to get this to work. Once the page www.24-timerssejlads.dk/sendtilmeld.php is loaded it seems to be working ok, but the email I receive is empty. Found someone saying it could be bacause I was using safe_mode. Checked in php.ini and safe mode is off.

My sendtilmeld.php looks like this :
Code:
<?php
   require_once "Mail.php";
   require_once 'Mail/mime.php';


   // Get user information entered on form.
   $Kontakt_FuldtNavn = $_REQUEST['Kontakt_FuldtNavn'] ;
   $baadnavn = $_REQUEST['baadnavn'] ;
   $foraar = $_REQUEST['foraar'] ;
   $efteraar = $_REQUEST['efteraar'] ;
   $starthavn = $_REQUEST['starthavn'] ;
   $tidligere = $_REQUEST['tidligere'] ;
   $senestaar = $_REQUEST['senestaar'] ;
   $Adresse = $_REQUEST['Adresse'] ;
   $postnr = $_REQUEST['postnr'] ;
   $by = $_REQUEST['by'] ;
   $email = $_REQUEST['email'] ;
   $dsklub = $_REQUEST['dsklub'] ;
   $baadtype = $_REQUEST['baadtype'] ;
   $skrogfarve = $_REQUEST['skrogfarve'] ;
   $sejlnr = $_REQUEST['sejlnr'] ;
   $lystal = $_REQUEST['lystal'] ;
   $lgd = $_REQUEST['lgd'] ;
   $brd = $_REQUEST['brd'] ;
   $depl = $_REQUEST['depl'] ;

   // Some info on who is sending.
   $from = "[email protected]";
   $to = "[email protected], $email";
   $subject = "24Timer - Tilmelding";
   
   // Some info on what smtp we are going to use.
   $host = "mail.24-timerssejlads.dk";
   $username = "[email protected]";
   $password = "somethingiknow";
   $crlf = "\n";
   
// Message start
$html = "<html>
<body>HTML TEST MESSAGE</body>
</html>";

$hdrs = array ('From' => $from,
'To' => $to,
'Subject' => $subject);

$mime = new Mail_Mime($crlf);
$mime->setHTMLBody($html);
print_r($html);

$body = $mime->get();
$headers = $mime->headers($hdrs);

$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>");
   }
?>


I have changed the message part until I find a solution.

// DKLeader
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Mail All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement