Send attachment file using mail () in PHP -


i had reference solution other post , tried modify content suit requirement.

here code implemented send attachment file via mail using php.

       $htmlbody = " mail contant here.... can use html tags here...";         $to = "foo@bar.com"; //recipient email address         $subject = "test email attachment"; //email subject         $headers = "from: foo@bar.com\r\nreply-to: foo@bar.com";         $random_hash = md5(date('r', time()));         $headers .= "\r\ncontent-type: multipart/mixed;          boundary=\"php-mixed-".$random_hash."\"";         // set file path here         $path = $_files["cv"]["name"];         $attachment = chunk_split(base64_encode(file_get_contents($path)));            //define body of message.         $message = "--php-mixed-$random_hash\r\n"."content-type: multipart/alternative;          boundary=\"php-alt-$random_hash\"\r\n\r\n";         $message .= "--php-alt-$random_hash\r\n"."content-type: text/plain;          charset=\"iso-8859-1\"\r\n"."content-transfer-encoding: 7bit\r\n\r\n";           //insert html message.         $message .= $htmlbody;         $message .="\r\n\r\n--php-alt-$random_hash--\r\n\r\n";           //include attachment         $message .= "--php-mixed-$random_hash\r\n"."content-type: application/zip;          name=\"$path\"\r\n"."content-transfer-encoding:          base64\r\n"."content-disposition: attachment\r\n\r\n";          $message .= $attachment;         $message .= "/r/n--php-mixed-$random_hash--";           //send email         $mail = mail( $to, $subject , $message, $headers );          echo $mail ? "mail sent" : "mail failed"; 

i able attachment file cant open it.

it show me error of "the application chose ("") not found. check file name or choose application."

can correct error..?

it seems problem relies in file name after download. server did job , sent email , rather client side problem.

  1. check filename extension , make sure same side sent it, if not make sure u correct php code naming function.

  2. make sure application reads filetype available on pc.

  3. try open file on different computer.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -