 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
Oliver77
Joined: 30 May 2009 Posts: 2
|
Posted: Sat May 30, 2009 8:57 am Post subject: Problem with HTML mail ... |
|
|
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 <me@fai.fr>";
$to = "TOI <toi@fai.fr>";
$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 |
|
 |
Oliver77
Joined: 30 May 2009 Posts: 2
|
Posted: Sun May 31, 2009 6:30 pm Post subject: [SOLVED] The solution to my problem ! |
|
|
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 <moi@fai.fr>";
$to = "TOI <toi@fai.fr.fr>";
$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 |
|
 |
boards
Joined: 26 Feb 2010 Posts: 1
|
Posted: Fri Feb 26, 2010 1:17 pm Post subject: |
|
|
we have a problem when sending the comments content via email to the users.y? _________________ mrsa infection
mrsa infection |
|
| Back to top |
|
 |
roommonkey
Joined: 21 Apr 2010 Posts: 1
|
Posted: Wed Apr 21, 2010 5:59 pm Post subject: |
|
|
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 = 'matt@example.co.uk';
$from = "website@example.co.uk";
$subject = "website email message ";
$host = "mail.example.co.uk";
$username = "website@example.co.uk";
$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 |
|
 |
brennanw
Joined: 20 May 2010 Posts: 8
|
Posted: Thu May 20, 2010 11:15 pm Post subject: |
|
|
roommonkey,
You are missing the <html><body></body></html> tags at the beginning and end. |
|
| Back to top |
|
 |
|
|
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
|
|