Jump to content

mail with attachment -- help please!!!!


lehi@here

Recommended Posts

hey guys, i got piece of code as following which use for sending email with attachment. however, it seems do not work at all.  the attachment did not come with the email, and part of the header information appeared in the mail body. can some body help me, please!

here is the header which appeared in email
[quote]

X-Mailer: PHP v4.4.2

MIME-Version: 1.0

Content-Type: multipart/related; boundary="32ce3c6108ebaa2cbfcfd23d906d7a1a"

Return-Path: email address here
X-OriginalArrivalTime: 16 Jan 2007 02:32:32.0401 (UTC) FILETIME=[9323D010:01C73916]


Content-Type: multipart/alternative

--32ce3c6108ebaa2cbfcfd23d906d7a1a

Content-Type: text/plain; charset="iso-8859-1"

Content-Transfer-Encoding: 8bit


mail content....


--32ce3c6108ebaa2cbfcfd23d906d7a1a--





[/quote]



here is the code
[quote]
// Obtain file upload vars
$fileatt      = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$fileatt_size = $_FILES['fileatt']['size'];

  $now = date("D M j G:i:s T Y"); 
  $eol="\r\n";
  $mime_boundary=md5(time());

  # Common Headers
  $headers = 'From: ' . $from .$eol;
  $headers .= 'Reply-To: ' . $from .$eol;
  $headers .= 'Return-Path: ' . $from .$eol;   
  $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
  $headers .= "X-Mailer: PHP v".phpversion().$eol;         

  # Boundry for marking the split & Multitype Headers
  $headers .= 'MIME-Version: 1.0'.$eol;
  $headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;

  $msg = "";   

    if (is_file($fileatt))
    {
           
      $handle=fopen($fileatt, 'rb');
      $f_contents=fread($handle, filesize($fileatt));
      $f_contents=chunk_split(base64_encode($f_contents));    //Encode The Data For Transition using base64_encode();
      fclose($handle);
     
      # Attachment
      $msg .= "--".$mime_boundary.$eol;
      $msg .= "Content-Type: ".$fileatt_type."; name=\"".$fileatt_name."\"".$eol;
      $msg .= "Content-Transfer-Encoding: base64".$eol;
      $msg .= "Content-Disposition: attachment; filename=\"".$fileatt_name."\"".$eol.$eol;
      $msg .= $f_contents.$eol.$eol;
     
    }


  # Setup for text OR html
  $msg .= "Content-Type: multipart/alternative".$eol;

  # Text Version
  $msg .= "--".$mime_boundary.$eol;
  $msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"".$eol;
  $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  $msg .= strip_tags(str_replace("<br>", "\n", $message)).$eol.$eol;

  # HTML Version
  $msg .= "--".$mime_boundary.$eol;
  $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
  $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  $msg .= $body.$eol.$eol;

  # Finished
  $msg .= "--".$mime_boundary."--".$eol.$eol; 
 

@mail($email,$subject,$msg,$headers);

[/quote]
Link to comment
https://forums.phpfreaks.com/topic/34368-mail-with-attachment-help-please/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.