Attachments are zero length in everything except gmail

[font=verdana, helvetica, sans-serif]
I have a class that I use for emailing. I’ve never needed attachments before, so I added the method to send them, but gmail seems to be the only place that I can see them. In Yahoo and mail.com they appear as zero-length files.

[php]

/**

  • Add an attachment to the email
  • @param STRING $path_to_file
  • @param STRING $attachment_name
  • @return VOID
    */
    function addAttachment($path_to_file, $attachment_name = null) {
    $this->attachments[$path_to_file] = $attachment_name;
    }

private function sendMailWithAttachment() {
// create the headers
$boundary = ‘jfd-’ . md5(date(‘r’, time()));
foreach ($this->recipients as $email => $name) {
// format to & from as 'name ’ or just email
$to = ($name != $email && $name) ? “$name <$email>” : $email;
$from = ($this->from_address[1]) ? “{$this->from_address[1]} <{$this->from_address[0]}>” : $this->from_address[0];
$header = “From: $from\n” .
“X-Mailer: FM5 1.0\n” .
“MIME-Version: 1.0\n” .
“Content-Type: multipart/mixed;\n” .
" boundary="$boundary"";
ob_start();
?>This is a multi-part message in MIME format.

–<?=$boundary?>

Content-Type: text/html; charset=“iso-8859-1”
Content-Transfer-Encoding: 7bit

<?=$this->html?>
	<?
	
	$message = ob_get_clean();
	
	foreach ($this->attachments as $system_filename => $save_as_filename) {
		if (!is_string($system_filename)) {
			$system_filename = $save_as_filename;
			$save_as_filename = basename($system_filename);
		}
		$filetype = mime_content_type($system_filename);
		$data = chunk_split(base64_encode(file_get_contents($system_filename)), 64);
		ob_start();
			?>

–<?=$boundary?>

Content-Type: <?=$filetype?>; name="<?=$save_as_filename?>"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="<?=$save_as_filename?>"

<?=$data?> <? $message .= ob_get_clean(); } // add the last closing boundary $message .= PHP_EOL ."--$boundary--"; // send the message mail($email, $this->subject, $message, $header, "-f{$this->from_address[0]}"); } }[/php][/font]
Sponsor our Newsletter | Privacy Policy | Terms of Service