How to send attachment file in email using PHP -
here way sending email using php. wish attach file type .doc, .docx, .pdf.
//send mail// $file_name = $_files['cv']['name']; $temp_name = "../abc/cv/" . $_files["cv"]["name"]; $file_type = $_files['cv']['type']; $message1 = "name : $name \n\n"; $message1.= "current designation : $designation \n\n"; $message1.= "current company : $current_company \n\n"; $message1.= "email : $email \n\n"; $message1.= "tel. : $tel \n\n"; $message1.= "preferred contact time : $contact_time \n\n"; $message1.= "apply position : $position \n\n"; $message1.= "earliest available date : $available_date \n\n"; $message1.= "expected salary : $salary \n\n"; //get extension of file $base = basename($file_name); $extension = substr($base, strlen($base)-4, strlen($base)); // mail sessenstials $from = $email; $to = "abc@hotmail.com"; $subject = $position." application form"; $message = $message1; // things need $file = $temp_name; $content = chunk_split(base64_encode(file_get_contents($file))); $uid = md5(uniqid(time())); //standard mail headers $header = "from: ".$email. "\r\n"; $header .= "reply to: ".$to."\r\n"; $header .= "mime-version: 1.0\r\n"; //declaring have nultiple kinds of email (plain text) $header .="content-type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .="this multi-part message in mime format. \r\n"; //plain text part $header .= "--".$uid."\r\n"; $header .= "content-type:text/plain: charset=iso-8859-1\r\n"; $header .= "content-transfer-encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; //file attachment $header .= "--".$uid."\r\n"; $header .= "content-type: ".$file_type."; name=\"".$file_name."\"\r\n"; $header .= "content-transfer-encoding: base64\r\n"; $header .= "content-disposition: attachment; filename=\"".$file_name."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; //send mail if(mail($to, $subject, "", $header)) { echo "success"; }else { echo "fail"; }
but when saw email, attachment file below:
--6eba57b85fe691e5db4019960b9911a9 content-type: image/jpeg; name="2.jpg" content-transfer-encoding: base64 content-disposition: attachment; filename="2.jpg" /9j/4aaqskzjrgabaqeayabgaad/2wbdaaibaqibaqicagicagicawudawmdawyebamfbwyhbwcg bwcicqsjcagkcachcg0kcgsmdawmbwkodw0mdgsmdaz/2wbdaqicagmdawydawymcacidawmdawm dawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdaz/waarcaiybymdasia ahebaxeb/8qahwaaaqubaqebaqeaaaaaaaaaaaecawqfbgcicqol/8qatraaagedawieawufbaqa aaf9aqidaaqrbrihmuege1fhbyjxfdkbkaeii0kxwrvs0fakm2jyggkkfhcygroljicokso0nty3 odk6q0rfrkdisuptvfvwv1hzwmnkzwznaglqc3r1dnd4exqdhiwgh4ijipktljwwl5izmqkjpkwm p
is have problem code ?
this solution reference other website.
Comments
Post a Comment