Mail function sending attachment Noname

Asked

Viewed 208 times

1

The email is successfully sent, but it seems that the attachment is not being sent correctly, because what comes is a file of 0 B, with the title of: Noname.

  • What are the causes for such a problem?
  • How to avoid it?
  • When I passed to wordpress, happened 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!";
    }
}

inserir a descrição da imagem aqui

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.