php - Forms to Send Attachment in Email -


i'm new here, after surfing through many pages, i've came form works , sends attachment email. however, when attachment not attached @ time form filled out, instead of thank page.

warning: file_get_contents(): filename cannot empty in /home/advem/public_html/careers.php on line 21

warning: cannot modify header information - headers sent (output started @ /home/advem/public_html/careers.php:21) in /home/advem/public_html/careers.php on line 61

however, email still gets sent me when attachment not used. appreciated.

<?php  if(!isset($_post['submit'])) {     //this page should not accessed directly. need submit form.     echo "error; need submit form!"; }      if(isset($_post['submit']))     {          //deal email         $to = 'email@testdesign.net';         $subject = 'new proof request';         $visitor_email = $_post['email'];          $message = strip_tags($_post['message']);         $sku = $_post['sku'];         $phone = $_post['phone'];         $name = $_post['name'];         $attachment = chunk_split(base64_encode(file_get_contents($_files['file']['tmp_name'])));         $filename = $_files['file']['name'];          $boundary =md5(date('r', time()));           //validate first if(empty($name)||empty($visitor_email))  {     echo "name , email mandatory!";     exit; }          $headers = "from: email@testdesign.net\r\nreply-to: $visitor_email";         $headers .= "\r\nmime-version: 1.0\r\ncontent-type: multipart/mixed; boundary=\"_1_$boundary\"";          $message="this 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  $name $sku $message $phone  --_2_$boundary-- --_1_$boundary content-type: application/octet-stream; name=\"$filename\"  content-transfer-encoding: base64  content-disposition: attachment   $attachment --_1_$boundary--";          mail($to, $subject, $message, $headers);         //done. redirect thank-you page.         header('location: thank-you-proof-request');          // function validate against email injection attempts function isinjected($str) {   $injections = array('(\n+)',               '(\r+)',               '(\t+)',               '(%0a+)',               '(%0d+)',               '(%08+)',               '(%09+)'               );   $inject = join('|', $injections);   $inject = "/$inject/i";   if(preg_match($inject,$str))     {     return true;   }   else     {     return false;   } }      } ?> 

i've tried answer @ following link, never have luck there either.

php - sending email attachment not show message content

i think should change code on line 21 to:

    $attachment = '';     $filename = '';     if($_files["file"]["error"] != 4 && file_exists($_files['file']['tmp_name'])){          $attachment = chunk_split(base64_encode(file_get_contents($_files['file']['tmp_name'])));         $filename = $_files['file']['name'];     } 

and on line 51 :

    if(!empty($filename)){         --_1_$boundary         content-type: application/octet-stream; name=\"$filename\"          content-transfer-encoding: base64          content-disposition: attachment           $attachment         --_1_$boundary--";     } 

i suggest use library sending email phpmailer, has lot of stuff can used , easy used.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -