I got an html class, but the output is eating " and the first leading character following from the HTML code...
ie was <a href="http://128.121.225.29....>
comes through as <a href=ttp://128.121.225.29...>
following is the whole goddamn class, i have no clue why it is eating the leading characters...... any ideas would be of great help. The variables passed to the functions escape " with \ and there is a function in the class which might be messing with it, unfortunately i have no idea how to fix the problem.
mike
html class
<?
// ----- DESCRIPTION --------------------------------------------
//
// MimeMail 1.0
// by Michel Heemskerk, michel@ism.nl
//
// PHP class for sending advanced email messages.
// ----- CONFIGURATION ------------------------------------------
//
// These variables depend on your system's configuration. Change
// them if necessary.
// $MIMETYPE_FILE = "/home/sites/site104/phplib/mime.types";
$MIMETYPE_FILE = "/usr/local/etc/httpd/conf/mime.types";
// $MIMETYPE_FILE = "/usr/lib/mime.types";
// ----- MANUAL -------------------------------------------------
//
// Step 1.
// Include and initiate the class like this:
//
// include("mimemail.php");
// $mimemail = new mimemail;
//
// Step 2.
// Set optional variables. These must be set before the send()
// function is called.
//
// $mimemail->subjectprefix = "offtopic";
//
// When this variable is set, it's contents will be placed
// in front of the message subject like this:
// "[offtopic] this is the subject"
//
// $mimemail->from = "user@internet.com";
//
// When set, this address will appear in the From: header. If
// not, it will appear as "current_user@http_host".
//
// $mimemail->replyto = "user@internet.com";
//
// Ditto. If not set, it will use the value of the "from"
// variable.
//
// $mimemail->signature = file("sig.txt");
// $mimemail->signature = $signature;
//
// The signature can be defined using two different ways: as
// an existing file (use the file() function as shown above)
// or as a variable or string.
//
// $mimemail->formatting = "text";
//
// This specifies the format in which mail is sent. Use
// "html" to send HTML messages and "text" to send in plain
// text. "te->xt" is default.
//
// $mimemail->attachment = "image.gif";
//
// This specifies a file to be attached to the mail message.
// Just use the filename, as shown above.
//
// Step 3.
// Send the message by calling the send() function like this:
//
// $mimemail->send($ADDRESS,$SUBJECT,file("mail.txt"));
// $mimemail->send($ADDRESS,$SUBJECT,$MESSAGE);
//
// Like the signature, the message contents can be specified
// in two different ways: as an existing file (use the file()
// function as shown above), or as a variable or string.
// ----- DO NOT EDIT BELOW THIS LINE ----------------------------
class mimemail
{
var $message;
var $subject;
var $to;
var $subjectprefix;
var $from;
var $replyto;
var $signature;
var $extraheaders;
var $formatting;
var $mimetypefile;
var $mimeversion;
var $appname;
var $boundary;
var $linelength;
var $hostname;
// ----------
function mimemail()
{
global $HTTP_HOST,$MIMETYPE_FILE;
$this->mimetypefile = $MIMETYPE_FILE;
$this->mimeversion = "1.0";
$this->appname = "MimeMail 1.0";
$this->boundary = "Boundary-=b".md5(uniqid(time()));
$this->linelength = "76";
$this->hostname = $HTTP_HOST;
}
// ----------
function validateaddress($address)
{
if (ereg("@",$address) && (sizeof(explode(".",$address)) - 1) > 0)
{
$return = 1;
}
else
{
$return = 0;
}
return $return;
}
// ----------
function makeaddress($address,$type)
{
switch($address)
{
case "":
switch($type)
{
case "to": $this->error(104); break;
case "from": $return = get_current_user()."@".$this->hostname; break;
case "replyto": $return = $this->from; break;
}
break;
default:
switch($this->validateaddress($address))
{
case 0:
switch($type)
{
case "to": $this->error(106); break;
case "from": $this->error(107); break;
case "replyto": $this->error(108); break;
}
break;
case 1:
$return = $address;
break;
}
break;
}
return $return;
}
// ----------
function error($code)
{
switch($code)
{
case 101: $error = "invalid or undefined message contents"; break;
case 103: $error = "undefined subject line"; break;
case 104: $error = "undefined recipient"; break;
case 105: $error = "invalid signature file"; break;
case 106: $error = "invalid recipient"; break;
case 107: $error = "invalid sender's address"; break;
case 108: $error = "invalid reply address"; break;
}
echo "[ ".$error." ]";
exit();
}
// ----------
function makebody($message,$signature)
{
if (!$message)
{
$this->error(101);
}
else
{
switch(gettype($message))
{
case "array":
for ($i = 0; $i < sizeof($message); $i++)
{
$return .= $message[$i]."\n";
}
break;
case "string":
default:
$return = $message;
break;
}
}
if ($signature)
{
switch(gettype($signature))
{
case "array":
switch($this->formatting)
{
case "html": $return .= "<BR><BR>"; break;
case "text": $return .= "\n\n"; break;
}
for ($i = 0; $i < sizeof($signature); $i++)
{
$return .= $signature[$i]."\n";
}
break;
case "string":
default:
switch($this->formatting)
{
case "html": $return .= "<BR><BR>"; break;
case "text": $return .= "\n\n"; break;
}
$return .= $signature."\n";
break;
}
}
return $return;
}
// ----------
function makesubject($subject)
{
switch($subject)
{
case "":
$this->error(103);
break;
default:
switch($this->subjectprefix)
{
case "": $return = $subject; break;
default: $return = "[".$this->subjectprefix."] ".$subject; break;
}
break;
}
return $return;
}
// ----------
function getmimetype($extension)
{
$array = file($this->mimetypefile);
for ($i = 0; $i < sizeof($array); $i++)
{
if (ereg($extension,$array[$i]))
{
$line = preg_split("/[\s,]+/",$array[$i]);
$return = $line[0];
break;
}
}
return $return;
}
// ----------
function makeheader($type)
{
switch($type)
{
case "pathreturn":
$return = "Return-Path: ".$this->makeaddress($this->replyto,"replyto")."\n";
break;
case "attachment":
$return = "Content-Type: ".$this->getmimetype(substr($this->attachment,(strrpos($this->attachment,".") + 1)))."; name=\"".$this->attachment."\"\n";
$return .= "Content-Transfer-Encoding: base64\n";
$return .= "Content-Disposition: attachment; filename=\"".$this->attachment."\"\n";
break;
case "from":
$return = "From: ".$this->makeaddress($this->from,"from")."\n";
break;
case "replyto":
$return = "Reply-To: ".$this->makeaddress($this->replyto,"replyto")."\n";
break;
case "xmailer":
$return = "X-Mailer: ".$this->appname." (powered by PHP/".phpversion().")\n";
break;
case "mimeversion":
$return = "MIME-Version: ".$this->mimeversion."\n";
break;
case "mixed":
$return = "Content-Type: multipart/mixed; boundary=\"".$this->boundary."\"\n\n";
break;
case "html":
$return = "Content-Type: ".$this->getmimetype("html")."; charset=\"iso-8859-1\"\n";
$return .= "Content-Transfer-Encoding: quoted-printable\n\n";
break;
case "text":
$return = "Content-Type: ".$this->getmimetype("txt")."; charset=\"iso-8859-1\"\n";
$return .= "Content-Transfer-Encoding: 7bit\n\n";
break;
case "boundary":
$return = "--".$this->boundary."\n";
break;
}
return $return;
}
// ----------
function makeattachment($filename)
{
$binary = base64_encode(fread(fopen($filename,"r"),filesize($filename)));
$return = "\n".$binary."\n\n";
return $return;
}
// ----------
function makeextraheaders()
{
$return = $this->makeheader("pathreturn");
$return .= $this->makeheader("from");
$return .= $this->makeheader("replyto");
$return .= $this->makeheader("xmailer");
$return .= $this->makeheader("mimeversion");
// $return .= $this->makeheader("mixed");
// $return .= $this->makeheader("boundary");
switch($this->formatting)
{
case "html":
$return .= $this->makeheader("html");
$return .= $this->message;
break;
case "":
case "text":
$return .= $this->makeheader("text");
$return .= $this->message;
break;
}
if ($this->attachment)
{
$return .= $this->makeheader("boundary");
$return .= $this->makeheader("attachment");
$return .= $this->makeattachment($this->attachment);
$return .= $this->makeheader("boundary");
}
return $return;
}
// ----------
function send($to,$subject,$message)
{
$this->message = $this->makebody($message,$this->signature);
$this->subject = $this->makesubject($subject);
$this->to = $this->makeaddress($to,"to");
$this->extraheaders = $this->makeextraheaders();
mail($this->to,$this->subject,"",$this->extraheaders);
}
// ----------
}
?>