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 ,

 Answers

40
 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" 
      ."--".$uid."rn"
      ."Content-type:text/plain; charset=iso-8859-1rn"
      ."Content-Transfer-Encoding: 7bitrnrn"
      .$message."rnrn"
      ."--".$uid."rn"
      ."Content-Type: application/octet-stream; name="".$filename.""rn"
      ."Content-Transfer-Encoding: base64rn"
      ."Content-Disposition: attachment; filename="".$filename.""rnrn"
      .$content."rnrn"
      ."--".$uid."--"; 
  return mail($to, $subject, "", $header);
 }
Wednesday, March 31, 2021
 
michele
answered 7 Months ago
86

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: http://confluence.jetbrains.com/display/PhpStorm/PHPUnit+Installation+via+Composer+in+PhpStorm

Related usability ticket: http://youtrack.jetbrains.com/issue/WI-18388

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

Wednesday, March 31, 2021
 
ojrac
answered 7 Months ago
49

Just exclude this when there is no attachment:

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

$attachment
--_1_$boundary--

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

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

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

    $email_message";

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

        $attachment
        --_1_$boundary--";
}
Wednesday, March 31, 2021
 
SkyNet
answered 7 Months ago
79

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
 
Nate
answered 5 Months ago
67
For sending mail with attachment using php mail().Try this code:

<?php

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


  $separator = md5(time());

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

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

  // 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)) {
  $mail_sent=true;
  echo "mail sent";
  } else {
  $mail_sent=false;
  echo "Error,Mail not sent";

 }
}

?>
Saturday, August 7, 2021
 
Optimight
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 :