Asked  2 Years ago    Answers:  5   Viewed   72 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

1
 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, August 17, 2022
 
1

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

Sunday, July 31, 2022
 
2

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--";
}
Thursday, November 3, 2022
 
4

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).

Sunday, November 6, 2022
4
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 = "[email protected]";
  $EmailFrom = "[email protected]";
  $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, September 17, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 

Browse Other Code Languages