Jump to content

Recommended Posts

I know there are several topics dealing with email attachments. I've studied all of them and can't seem to wrap my head around what I'm doing wrong here. The received email shows 1 Attachment as 'Part 1.2 0 bytes'... Email source shows a null for attachment 'file' and 'filename'. Also I'm trying to attach 2 files, both are zips. Any help is appreciated. Here is the most pertinent parts of my code:

 

 

define("ATTACH_FOLDER", INFUSIONS . "news_letter/attach/");

include INFUSIONS."news_letter/include/attach_include.php";
switch ($delivery) {

 case ($delivery == 'uem'):

include INCLUDES."sendmail_include.php";
// Mail send routine for single/multiple/all users

 $error = "";

$result = dbquery("SELECT nl_id, nl_style FROM ".DB_NEWS_LETTER." WHERE nl_id='".$_POST['nl_id']."'");

 $data=dbarray($result);

 $style = $data['nl_style'];

 if ($style=="1-1col" || $style=="1-2col" || $style=="1-3col") {

  $template = "tmpl1.php"; }

 else if ($style=="2-1col" || $style=="2-2col" || $style=="2-3col") {

  $template = "tmpl2.php"; }

 else if ($style=="3-1col" || $style=="3-2col" || $style=="3-3col") {

  $template = "tmpl3.php"; }

 else if ($style=="4-1col" || $style=="4-2col" || $style=="4-3col") {

  $template = "tmpl4.php"; }

 else if ($style=="5-1col" || $style=="5-2col" || $style=="5-3col") {

  $template = "tmpl5.php"; }
 $subject = stripslashes($_POST['subject']);

 $from = $settings['siteemail'];

 $usrtxt = stripslashes($_POST['msg']);

 $format = $_POST['format'];

 $send_array = ($_POST['sendto']);

 $list = implode(",",$send_array);

 $to_email = $list;

 $list_array = explode(",",$to_email);

 reset($list_array);

include INFUSIONS."news_letter/templates/$template";

require_once INFUSIONS."news_letter/include/html2text.php";

 $html_version = $content;

 $text_version = html2text($html_version);

// boundary

$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  $content = $html_version;

  $headers = "From: $from";

 if($_POST['fileattach'] == "yes") {

 $file_array = ATTACH_FOLDER.($_POST['attach_files']); }

 $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";

 $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $content . "\n\n";

 $message .= "--{$mime_boundary}\n";

// preparing attachments

  for($x=0;$x<count($file_array);$x++){

  $file = fopen($file_array[$x],"rb");

  $data = fread($file,filesize($file_array[$x]));

  fclose($file);

  $data = chunk_split(base64_encode($data));

  $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$file[$x]\"\n" .

  "Content-Disposition: attachment;\n" . " filename=\"$file[$x]\"\n" .

  "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";

  $message .= "--{$mime_boundary}\n";

  }

 }

foreach($list_array AS $to_mail) {

 

Link to comment
https://forums.phpfreaks.com/topic/276717-cant-see-atachment-problems/
Share on other sites

Check the data variable and post out the result.

 

for($x=0;$x<count($file_array);$x++){

  $file = fopen($file_array[$x],"rb");

  $data = fread($file,filesize($file_array[$x]));

  fclose($file);

// here 
echo '<pre'>.print_r($data, true).'</pre'>; exit; 

 $data = chunk_split(base64_encode($data)

OK; I tried your suggestion and nothing is printed to the screen however; I have made significant progress. I now get the 2 or 3 attachments showing up in the received email; filenames are correct but; bytes are still zero(0)... and I get an error log entry on my cms that says cannot stat filesize. This is my cms errorlog entry:

 

news_letter/news_letter_admin
filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for For_Steven.zip Line: 172

 

Here is the code changes I made; I'm almost there:

 

 

  $content = $html_version;
  $headers = "From: $from";
 if($_POST['fileattach'] == "yes") {
 $file_array = ($_POST['attach_files']);
 $file_list = implode(",",$file_array);
 $my_list = $file_list;
 $new_list = explode(",",$my_list);
 reset($new_list);
}
 $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
 $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $content . "\n\n";
 $message .= "--{$mime_boundary}\n";
// preparing attachments
  foreach($new_list AS $new_file) {
  $handle = fopen(ATTACH_FOLDER.$new_file, "rb");
  $data = fread($handle, filesize($new_file));
  fclose($handle);
  $split = chunk_split(base64_encode($data));
  $message .= "Content-Type: {\"application/zip\"};\n" . " name=\"$new_file\"\n" .
  "Content-Disposition: attachment;\n" . " filename=\"$new_file\"\n" .
  "Content-Transfer-Encoding: base64\n\n" . $split . "\n\n";
  $message .= "--{$mime_boundary}\n";
  }
 }
 
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.