SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Jun 8, 2007, 02:19 #1
shows html code while sending mail problem ??
Hello forums !!
I am using my mail function to send the mail, mail successfully goes but the problem is its shows all the html codes and also the name is blank in the from section (Note: I am using outlook express)
i had used the following code:
PHP Code:<?php
class Mailer{
var $to;
var $from;
var $cc;
var $bcc;
var $headers;
var $subject;
var $message;
function Mailer(){
$this->to = "";
$this->from = "";
$this->cc = "";
$this->bcc = "";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: '.$this->to . "\r\n";
$headers .= 'From: '.$this->from . "\r\n";
$headers .= 'Reply-To: '.$this->from . "\r\n";
$headers .= 'Cc: '.$this->cc . "\r\n";
$headers .= 'Bcc: '.$this->bcc . "\r\n";
$this->headers = $headers;
}
function setSubject(){
$this->subject = "subjects goes here..";
}
function setMessage($message){
# set Message
$message = <<<EOF
<html>
<head>
</head>
<body>
<p> </p>
<table width="455" border="0" align="center" cellpadding="0" cellspacing="10" bgcolor="#FFFFFF">
<tr>
<td width="88"><span class="field">Message</span></td>
<td width="289"><span class="fieldValue">$message</span></td>
</tr>
</table>
</body>
</html>
EOF;
$this->message = $message;
}
function sendMail(){
return mail($this->to, $this->subject, $this->message, $this->headers);
}
}
/**
* Usage
*/
$Mailer = new Mailer();
$Mailer->setSubject();
$Mailer->setMessage("Message goes here...");
$Mailer->sendMail();
?>
Thanks in advance to all of you
-
Jun 8, 2007, 09:59 #2
- Join Date
- May 2005
- Location
- London, ON
- Posts
- 360
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You need to add the proper headers to tell the email client what to show if the user is HTML-enabled and what to show if they are not. Here is an example taken from a script I wrote for my university's research department that should get you started:
PHP Code://add From: header
$headers = "From: Research Funding <res-fund@uwo.ca>\r\n";
//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";
//unique boundary
$boundary = uniqid("HTMLDEMO");
//tell e-mail client this e-mail contains alternate versions
$headers .= "Content-Type: multipart/alternative" .
"; boundary = $boundary\r\n\r\n";
//message to people with clients who don't understand MIME
$headers .= "This is a MIME encoded message.\r\n\r\n";
//plain text version of message
$headers .= "--$boundary\r\n" .
"Content-Type: text/plain; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: 7bit\r\n\r\n";
//HTML version of message
$headers .= "--$boundary\r\n" .
"Content-Type: text/html; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: 7bit\r\n\r\n";
-
Jun 8, 2007, 10:01 #3
- Join Date
- May 2005
- Location
- London, ON
- Posts
- 360
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Also, I just did a quick search. I'm pretty sure this is the article I got my info from:
http://www.zend.com/zend/trick/html-email.php
Bookmarks