Asked  7 Months ago    Answers:  5   Viewed   30 times

How to send the email with resume attachment ,

i take snippet from this place Click here

In this site, snippet works fine,

Even i got the mail, but attachment is not working, am getting attment as noname with 0kb

size file, What is Issue in that snippet ,


 function mail_attachment($to, $subject, $message, $from, $file) {
  // $file should include path and filename
  $filename = basename($file);
  $file_size = filesize($file);
  $content = chunk_split(base64_encode(file_get_contents($file))); 
  $uid = md5(uniqid(time()));
  $from = str_replace(array("r", "n"), '', $from); // to prevent email injection
  $header = "From: ".$from."rn"
      ."MIME-Version: 1.0rn"
      ."Content-Type: multipart/mixed; boundary="".$uid.""rnrn"
      ."This is a multi-part message in MIME format.rn" 
      ."Content-type:text/plain; charset=iso-8859-1rn"
      ."Content-Transfer-Encoding: 7bitrnrn"
      ."Content-Type: application/octet-stream; name="".$filename.""rn"
      ."Content-Transfer-Encoding: base64rn"
      ."Content-Disposition: attachment; filename="".$filename.""rnrn"
  return mail($to, $subject, "", $header);
Wednesday, March 31, 2021
answered 7 Months ago

You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer.

This blog post has all the details (with pictures) to successfully configure IDE for such scenario:

Related usability ticket:

P.S. The WI-18388 ticket is already fixed in v8.0

Wednesday, March 31, 2021
answered 7 Months ago

Just exclude this when there is no attachment:

Content-Type: application/octet-stream; name="$filename" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 


For example, only appending it to $message when the filename is not empty:

$message = "This is a multi-part message in MIME format.
    Content-Type: multipart/alternative; boundary="_2_$boundary"

    Content-Type: text/plain; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit


if (!empty($filename))
   $message .= " --_1_$boundary
        Content-Type: application/octet-stream; name="$filename" 
        Content-Transfer-Encoding: base64 
        Content-Disposition: attachment 

Wednesday, March 31, 2021
answered 7 Months ago

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Saturday, May 29, 2021
answered 5 Months ago
For sending mail with attachment using php mail().Try this code:


 //If there is no error, send the email
 if(isset($_POST['ur_submit_button_name'])) {
  $EmailTo = "";
  $EmailFrom = "";
  $EmailSubject = "The Email Subject";

  $separator = md5(time());

  // carriage return type (we use a PHP end of line constant)
  $eol = PHP_EOL;

  // attachment name
  $filename = "";//store that zip file in ur root directory
  $attachment = chunk_split(base64_encode(file_get_contents('')));

  // main header
  $headers  = "From: ".$from.$eol;
  $headers .= "MIME-Version: 1.0".$eol; 
  $headers .= "Content-Type: multipart/mixed; boundary="".$separator.""";

  // no more headers after this, we start the body! //

  $body = "--".$separator.$eol;
  $body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
  $body .= "This is a MIME encoded message.".$eol;

  // message
  $body .= "--".$separator.$eol;
  $body .= "Content-Type: text/html; charset="iso-8859-1"".$eol;
  $body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
  $body .= $message.$eol;

  // attachment
  $body .= "--".$separator.$eol;
  $body .= "Content-Type: application/octet-stream; name="".$filename.""".$eol; 
  $body .= "Content-Transfer-Encoding: base64".$eol;
  $body .= "Content-Disposition: attachment".$eol.$eol;
  $body .= $attachment.$eol;
  $body .= "--".$separator."--";

  // send message
  if (mail($to, $subject, $body, $headers)) {
  echo "mail sent";
  } else {
  echo "Error,Mail not sent";


Saturday, August 7, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :