0

I'm trying to attach two files to a single email (see code below) but I only receive one of them in the email I get.

if(isset($_POST['submits']))
{
    //The form has been submitted, prep a nice thank you message
    $output = '<h1>Thanks for your file and message!</h1>';
    //Set the form flag to no display (cheap way!)
    $flags = 'style="display:none;"';

    //Deal with the email
    $to = 'info@domain.org';
    $subject = 'cv and image upload';

    $message = strip_tags($_POST['message']);
    $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
    $filename = $_FILES['file']['name'];

    $boundary =md5(date('r', time())); 

    $headers = "From: info@domain.org\r\nReply-To: info@domain.org";
    $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";

    $message="This is a multi-part message in MIME format.--_1_$boundaryContent-Type: multipart/alternative; boundary=\"_2_$boundary\"--_2_$boundaryContent-Type: text/plain; charset=\"iso-8859-1\"Content-Transfer-Encoding: 7bit$message--_2_$boundary----_1_$boundaryContent-Type: application/octet-stream; name=\"$filename\" Content-Transfer-Encoding: base64 Content-Disposition: attachment $attachment--_1_$boundary--";

    mail($to, $subject, $message, $headers);
}
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Quba
  • 1
  • 1

1 Answers1

0

try to use javascript to add more file input with different name to the form.or if ui isnt important you can use more inputs. you cant upload two files from same input at once. and finaly use smtp insted of mail().