Modif pour gérer si il n'y a pas de fichier joint

This commit is contained in:
Rodolphe Quiedeville 2003-07-07 10:04:20 +00:00
parent ca670b0a7d
commit c49dc7978f

View File

@ -19,7 +19,8 @@ to chunk_split
/* Note: if you don't have base64_encode on your sytem it will not work */ /* Note: if you don't have base64_encode on your sytem it will not work */
// simple class that encapsulates mail() with addition of mime file attachment. // simple class that encapsulates mail() with addition of mime file attachment.
class CMailFile { class CMailFile
{
var $subject; var $subject;
var $addr_to; var $addr_to;
var $text_body; var $text_body;
@ -28,16 +29,22 @@ class CMailFile {
var $mime_boundary = "--==================_846811060==_"; var $mime_boundary = "--==================_846811060==_";
var $smtp_headers; var $smtp_headers;
function CMailFile($subject,$to,$from,$msg,$filename,$mimetype = "application/octet-stream", $mime_filename = false) { function CMailFile($subject,$to,$from,$msg,$filename,$mimetype = "application/octet-stream", $mime_filename = false)
{
$this->subject = $subject; $this->subject = $subject;
$this->addr_to = $to; $this->addr_to = $to;
$this->smtp_headers = $this->write_smtpheaders($from); $this->smtp_headers = $this->write_smtpheaders($from);
$this->text_body = $this->write_body($msg); $this->text_body = $this->write_body($msg, $filename);
if (strlen($filename))
{
$this->text_encoded = $this->attach_file($filename,$mimetype,$mime_filename); $this->text_encoded = $this->attach_file($filename,$mimetype,$mime_filename);
$this->mime_headers = $this->write_mimeheaders($filename, $mime_filename); $this->mime_headers = $this->write_mimeheaders($filename, $mime_filename);
} }
}
function attach_file($filename,$mimetype,$mime_filename) { function attach_file($filename,$mimetype,$mime_filename)
{
$encoded = $this->encode_file($filename); $encoded = $this->encode_file($filename);
if ($mime_filename) $filename = $mime_filename; if ($mime_filename) $filename = $mime_filename;
$out = "--" . $this->mime_boundary . "\n"; $out = "--" . $this->mime_boundary . "\n";
@ -47,11 +54,13 @@ class CMailFile {
$out = $out . $encoded . "\n"; $out = $out . $encoded . "\n";
$out = $out . "--" . $this->mime_boundary . "--" . "\n"; $out = $out . "--" . $this->mime_boundary . "--" . "\n";
return $out; return $out;
// added -- to notify email client attachment is done // added -- to notify email client attachment is done
} }
function encode_file($sourcefile) { function encode_file($sourcefile)
if (is_readable($sourcefile)) { {
if (is_readable($sourcefile))
{
$fd = fopen($sourcefile, "r"); $fd = fopen($sourcefile, "r");
$contents = fread($fd, filesize($sourcefile)); $contents = fread($fd, filesize($sourcefile));
$encoded = my_chunk_split(base64_encode($contents)); $encoded = my_chunk_split(base64_encode($contents));
@ -60,15 +69,20 @@ class CMailFile {
return $encoded; return $encoded;
} }
function sendfile() { function sendfile()
{
$headers = $this->smtp_headers . $this->mime_headers; $headers = $this->smtp_headers . $this->mime_headers;
$message = $this->text_body . $this->text_encoded; $message = $this->text_body . $this->text_encoded;
return mail($this->addr_to,$this->subject,$message,$headers); return mail($this->addr_to,$this->subject,$message,$headers);
} }
function write_body($msgtext) { function write_body($msgtext, $filename)
{
if (strlen($filename))
{
$out = "--" . $this->mime_boundary . "\n"; $out = "--" . $this->mime_boundary . "\n";
$out = $out . "Content-Type: text/plain; charset=\"us-ascii\"\n\n"; $out = $out . "Content-Type: text/plain; charset=\"us-ascii\"\n\n";
}
$out = $out . $msgtext . "\n"; $out = $out . $msgtext . "\n";
return $out; return $out;
} }
@ -83,7 +97,8 @@ class CMailFile {
return $out; return $out;
} }
function write_smtpheaders($addr_from) { function write_smtpheaders($addr_from)
{
$out = "From: $addr_from\n"; $out = "From: $addr_from\n";
$out = $out . "Reply-To: $addr_from\n"; $out = $out . "Reply-To: $addr_from\n";
$out = $out . "X-Mailer: PHP3\n"; $out = $out . "X-Mailer: PHP3\n";