Function sending mail attachment noname

1

The email is sent successfully, but it seems that the attachment is not being sent correctly, because what arrives is a 0 B file, titled: noname .

p>
  • What are the causes for such a problem?
  • How do you avoid it?
  • When I moved to wordpress, it started to give this problem, but when the page was static, it worked.
  

Code used:

function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {

    $file = isset($_FILES["file"]) ? $_FILES["file"] : FALSE; 

    if(file_exists($file["tmp_name"]) and !empty($file)){

    $fp = fopen($_FILES["file"]["tmp_name"],"rb"); 
    $anexo = fread($fp,filesize($_FILES["file"]["tmp_name"])); 
    $anexo = base64_encode($anexo); 

    fclose($fp);

    $anexo = chunk_split($anexo); 

    }


    $uid = md5(uniqid(time()));
    $name = basename($file);
    $header = "From: ".$from_name." <".$from_mail.">\r\n";
    $header .= "Reply-To: ".$replyto."\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
    $header .= "This is a multi-part message in MIME format.\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-type:text/html; charset=UTF-8\r\n";
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $header .= $message."\r\n\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
    $header .= "Content-Transfer-Encoding: base64\r\n";
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
    $header .= $anexo."\r\n\r\n";
    $header .= "--".$uid."--";



    wp_mail($mailto, $subject, $message, $header, $attachments = array($anexo) );

    if (mail($mailto, $subject, "", $header)) {
        //echo "Foiçe!";
    } else {
        //echo "ERROR!";
    }
}

    
asked by anonymous 11.06.2015 / 18:22

0 answers