Php 还有一个查询移动文件上传问题

Php 还有一个查询移动文件上传问题,php,forms,email,jquery-mobile,attachment,Php,Forms,Email,Jquery Mobile,Attachment,首先,我已经看到了很多关于类似问题的建议,但是,我还没有找到任何完全符合我正在尝试做的事情的建议 我有一个表单可以发布到PHP电子邮件提交,在表单的末尾,我希望用户可以选择从摄像头应用程序或gallery(我听说iPhone不允许访问摄像头应用程序,但Androids允许)附加多张照片,并通过一封漂亮的小电子邮件发送。我在我的所有附件行上都不断出现未定义的索引错误。现在,我已经用尽了我的copy-fu疑难解答,现在我求助于询问那些实际上比我更了解PHP语法的人。这是我表格的结尾,附件部分(整个页

首先,我已经看到了很多关于类似问题的建议,但是,我还没有找到任何完全符合我正在尝试做的事情的建议

我有一个表单可以发布到PHP电子邮件提交,在表单的末尾,我希望用户可以选择从摄像头应用程序或gallery(我听说iPhone不允许访问摄像头应用程序,但Androids允许)附加多张照片,并通过一封漂亮的小电子邮件发送。我在我的所有附件行上都不断出现未定义的索引错误。现在,我已经用尽了我的copy-fu疑难解答,现在我求助于询问那些实际上比我更了解PHP语法的人。这是我表格的结尾,附件部分(整个页面非常广泛和详细,如果需要,我可以显示,但这是唯一让我头疼的部分…):


(所有其他选项,然后…)

上传照片:
*请只按一次提交按钮。大尺寸照片需要更长的上传时间

然后是我的整个PHP页面:

<?php

$MOfirstname = $_POST['MOfirstname'];
$MOlastname = $_POST['MOlastname'];
$MOcompany = $_POST['MOcompany'];
$MOemail = $_POST['MOemail'];
$MOphone = $_POST['MOphone'];
$MOmodelnumber = $_POST['MOmodelnumber'];
$MOvoltage = $_POST['MOvoltage'];
$MOoperation = $_POST['MOoperation'];
$MOfused = $_POST['MOfused'];
$MOtriptype = $_POST['MOtriptype'];
$MOfusesize = $_POST['MOfusesize'];
$MOquantity = $_POST['MOquantity'];
$MOcomments = $_POST['MOcomments'];
$MOdelivery = $_POST['MOdelivery'];
$MOmailinglist = $_POST['MOmailinglist'];
$MO_Function = implode(", ", $_POST['MO_Function']);
$MOquote = implode(", ", $_POST['MOquote']);
$MOAux = implode(", ", $_POST['MOAux']);
$MOAuxSwitchSize = $_POST['MOAuxSwitchSize'];
$MOAuxShuntTripVoltage = $_POST['MOAuxShuntTripVoltage'];
$MOBellAlarm_OTS_Voltage = $_POST['MOBellAlarm_OTS_Voltage'];
$MOBellAlarm_OTS_Operation = $_POST['MOBellAlarm_OTS_Operation'];

$attachment1 = $field_file = $_POST['attachment1'];
$tmpName1 = $_FILES['attachment1']['tmp_name1'];
$fileType1 = $_FILES['attachment1']['type1'];
$fileName1 = $_FILES['attachment1']['name1'];
$attachment2 = $field_file = $_POST['attachment2'];
$tmpName2 = $_FILES['attachment2']['tmp_name2'];
$fileType2 = $_FILES['attachment2']['type2'];
$fileName2 = $_FILES['attachment2']['name2'];
$attachment3 = $field_file = $_POST['attachment3'];
$tmpName3 = $_FILES['attachment3']['tmp_name3'];
$fileType3 = $_FILES['attachment3']['type3'];
$fileName3 = $_FILES['attachment3']['name3'];
$attachment4 = $field_file = $_POST['attachment4'];
$tmpName4 = $_FILES['attachment4']['tmp_name4'];
$fileType4 = $_FILES['attachment4']['type4'];
$fileName4 = $_FILES['attachment4']['name4'];
$attachment5 = $field_file = $_POST['attachment5'];
$tmpName5 = $_FILES['attachment5']['tmp_name5'];
$fileType5 = $_FILES['attachment5']['type5'];
$fileName5 = $_FILES['attachment5']['name5'];

if(empty($MOfirstname)||empty($MOemail)||empty($MOlastname)||empty($MOcompany)||empty($MOphone)) 
{
    echo "<div style ='font:36px Arial,tahoma,sans-serif;color:#ff0000'>Please click the Back button and fill in all contact information.</div>";
    exit;
}

$to = "myemail@privacy.com";
$email_from = 'myemail@privacy.com';
$email_subject = "New Mobile Submission";
$email_body = "You have received a new query from $MOfirstname $MOlastname at $MOcompany about a $MOmodelnumber. They can be reached at $MOphone or $MOemail.\n".

    "Here is the request:\n \n
    Quantity: $MOquantity
    Model: $MOmodelnumber
    Frame Size: $MOvoltage
    Operation: $MOoperation
    Fused: $MOfused
    Fuse Size: $MOfusesize
    Trip Type: $MOtriptype
    Functions: $MO_Function
    Auxillary Devices: $MOAux
        Auxillary Switch Size: $MOAuxSwitchSize
        Auxillary Shunt Trip Voltage: $MOAuxShuntTripVoltage
        Bell Alarm/OTS Operation = $MOBellAlarm_OTS_Operation
        Bell Alarm/OTS Voltage: $MOBellAlarm_OTS_Voltage
    Additional Info: $MOcomments
    Mailing List: $MOmailinglist


    They would like a quote for the following:
        $MOquote

    With a desired delivery of:
        $MOdelivery";


$headers = "From:myemail@privacy.com \r\n";
$headers .= "Reply-To: $MOemail \r\n"; 
    {
          /* Reading file ('rb' = read binary)  */
          $file1 = fopen($tmpName1,'rb');
          $data1 = fread($file1,filesize($tmpName1));
          fclose($file1);

          $file2 = fopen($tmpName2,'rb');
          $data2 = fread($file2,filesize($tmpName2));
          fclose($file2);

          $file3 = fopen($tmpName3,'rb');
          $data3 = fread($file3,filesize($tmpName3));
          fclose($file3);

          $file4 = fopen($tmpName4,'rb');
          $data4 = fread($file4,filesize($tmpName4));
          fclose($file4);

          $file5 = fopen($tmpName5,'rb');
          $data5 = fread($file5,filesize($tmpName5));
          fclose($file5);

            /* a boundary string */
          $randomVal = md5(time());
          $mimeBoundary = "==Multipart_Boundary_x{$randomVal}x";

          /* Header for File Attachment */
          $headers .= "\nMIME-Version: 1.0\n";
          $headers .= "Content-Type: multipart/mixed;\n" ;
          $headers .= " boundary=\"{$mimeBoundary}\"";

          /* Multipart Boundary above message */
          $email_body = "This is a multi-part message in MIME format.\n\n" .
          "--{$mimeBoundary}\n" .
          "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
          "Content-Transfer-Encoding: 7bit\n\n" .
          $email_body . "\n\n";

          /* Encoding file data */
          $data1 = chunk_split(base64_encode($data1));
          $data2 = chunk_split(base64_encode($data2));
          $data3 = chunk_split(base64_encode($data3));
          $data4 = chunk_split(base64_encode($data4));
          $data5 = chunk_split(base64_encode($data5));

          /* Adding attchment-file to message*/
          $email_body .= "--{$mimeBoundary}\n" .
          "Content-Type: {$fileType};\n" .
          " name=\"{$fileName1}\"\n" .
          "Content-Transfer-Encoding: base64\n\n" .
          $data1 . "\n\n" .
          "--{$mimeBoundary}--\n";

          $email_body .= "--{$mimeBoundary}\n" .
          "Content-Type: {$fileType};\n" .
          " name=\"{$fileName2}\"\n" .
          "Content-Transfer-Encoding: base64\n\n" .
          $data2 . "\n\n" .
          "--{$mimeBoundary}--\n";

          $email_body .= "--{$mimeBoundary}\n" .
          "Content-Type: {$fileType};\n" .
          " name=\"{$fileName3}\"\n" .
          "Content-Transfer-Encoding: base64\n\n" .
          $data3 . "\n\n" .
          "--{$mimeBoundary}--\n";

          $email_body .= "--{$mimeBoundary}\n" .
          "Content-Type: {$fileType};\n" .
          " name=\"{$fileName4}\"\n" .
          "Content-Transfer-Encoding: base64\n\n" .
          $data4 . "\n\n" .
          "--{$mimeBoundary}--\n";

          $email_body .= "--{$mimeBoundary}\n" .
          "Content-Type: {$fileType};\n" .
          " name=\"{$fileName5}\"\n" .
          "Content-Transfer-Encoding: base64\n\n" .
          $data5 . "\n\n" .
          "--{$mimeBoundary}--\n";
    }
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;
    }
}

if(IsInjected($MOemail))
{
    echo "Bad email value!";
    exit;
}
@mail($to,$email_subject,$email_body,$headers);
header("Location: thank-you.html");

?> 

好的…最终,我希望附件作为附件添加到电子邮件中,但我不希望用户必须附加所有5张照片


…我相信有一种比我处理这件事的方式简单得多的方法,但我愿意接受建议…

好吧,我想缺乏回应是一种迹象,表明我处理这件事的方式过于复杂和/或毫无意义…因此,没有人想碰它

我能够让它与PHPMailer一起工作

<label for="attachments">Upload Photos:</label>
            <input type="file" name="attachment1" id="attachment1" class="ui-input-text" />
            <input type="file" name="attachment2" id="attachment2" class="ui-input-text" />
            <input type="file" name="attachment3" id="attachment3" class="ui-input-text" />
            <input type="file" name="attachment4" id="attachment4" class="ui-input-text" />
            <input type="file" name="attachment5" id="attachment5" class="ui-input-text" />
            <p>*Please only press the Submit button once. Large sized photos require longer time to upload</p>
<input type="submit" name="submit" value="Submit Request" data-disabled="false">
<?php

$MOfirstname = $_POST['MOfirstname'];
$MOlastname = $_POST['MOlastname'];
$MOcompany = $_POST['MOcompany'];
$MOemail = $_POST['MOemail'];
$MOphone = $_POST['MOphone'];
$MOmodelnumber = $_POST['MOmodelnumber'];
$MOvoltage = $_POST['MOvoltage'];
$MOoperation = $_POST['MOoperation'];
$MOfused = $_POST['MOfused'];
$MOtriptype = $_POST['MOtriptype'];
$MOfusesize = $_POST['MOfusesize'];
$MOquantity = $_POST['MOquantity'];
$MOcomments = $_POST['MOcomments'];
$MOdelivery = $_POST['MOdelivery'];
$MOmailinglist = $_POST['MOmailinglist'];
$MO_Function = implode(", ", $_POST['MO_Function']);
$MOquote = implode(", ", $_POST['MOquote']);
$MOAux = implode(", ", $_POST['MOAux']);
$MOAuxSwitchSize = $_POST['MOAuxSwitchSize'];
$MOAuxShuntTripVoltage = $_POST['MOAuxShuntTripVoltage'];
$MOBellAlarm_OTS_Voltage = $_POST['MOBellAlarm_OTS_Voltage'];
$MOBellAlarm_OTS_Operation = $_POST['MOBellAlarm_OTS_Operation'];

$attachment1 = $field_file = $_POST['attachment1'];
$tmpName1 = $_FILES['attachment1']['tmp_name1'];
$fileType1 = $_FILES['attachment1']['type1'];
$fileName1 = $_FILES['attachment1']['name1'];
$attachment2 = $field_file = $_POST['attachment2'];
$tmpName2 = $_FILES['attachment2']['tmp_name2'];
$fileType2 = $_FILES['attachment2']['type2'];
$fileName2 = $_FILES['attachment2']['name2'];
$attachment3 = $field_file = $_POST['attachment3'];
$tmpName3 = $_FILES['attachment3']['tmp_name3'];
$fileType3 = $_FILES['attachment3']['type3'];
$fileName3 = $_FILES['attachment3']['name3'];
$attachment4 = $field_file = $_POST['attachment4'];
$tmpName4 = $_FILES['attachment4']['tmp_name4'];
$fileType4 = $_FILES['attachment4']['type4'];
$fileName4 = $_FILES['attachment4']['name4'];
$attachment5 = $field_file = $_POST['attachment5'];
$tmpName5 = $_FILES['attachment5']['tmp_name5'];
$fileType5 = $_FILES['attachment5']['type5'];
$fileName5 = $_FILES['attachment5']['name5'];

if(empty($MOfirstname)||empty($MOemail)||empty($MOlastname)||empty($MOcompany)||empty($MOphone)) 
{
    echo "<div style ='font:36px Arial,tahoma,sans-serif;color:#ff0000'>Please click the Back button and fill in all contact information.</div>";
    exit;
}

$to = "myemail@privacy.com";
$email_from = 'myemail@privacy.com';
$email_subject = "New Mobile Submission";
$email_body = "You have received a new query from $MOfirstname $MOlastname at $MOcompany about a $MOmodelnumber. They can be reached at $MOphone or $MOemail.\n".

    "Here is the request:\n \n
    Quantity: $MOquantity
    Model: $MOmodelnumber
    Frame Size: $MOvoltage
    Operation: $MOoperation
    Fused: $MOfused
    Fuse Size: $MOfusesize
    Trip Type: $MOtriptype
    Functions: $MO_Function
    Auxillary Devices: $MOAux
        Auxillary Switch Size: $MOAuxSwitchSize
        Auxillary Shunt Trip Voltage: $MOAuxShuntTripVoltage
        Bell Alarm/OTS Operation = $MOBellAlarm_OTS_Operation
        Bell Alarm/OTS Voltage: $MOBellAlarm_OTS_Voltage
    Additional Info: $MOcomments
    Mailing List: $MOmailinglist


    They would like a quote for the following:
        $MOquote

    With a desired delivery of:
        $MOdelivery";


$headers = "From:myemail@privacy.com \r\n";
$headers .= "Reply-To: $MOemail \r\n"; 
    {
          /* Reading file ('rb' = read binary)  */
          $file1 = fopen($tmpName1,'rb');
          $data1 = fread($file1,filesize($tmpName1));
          fclose($file1);

          $file2 = fopen($tmpName2,'rb');
          $data2 = fread($file2,filesize($tmpName2));
          fclose($file2);

          $file3 = fopen($tmpName3,'rb');
          $data3 = fread($file3,filesize($tmpName3));
          fclose($file3);

          $file4 = fopen($tmpName4,'rb');
          $data4 = fread($file4,filesize($tmpName4));
          fclose($file4);

          $file5 = fopen($tmpName5,'rb');
          $data5 = fread($file5,filesize($tmpName5));
          fclose($file5);

            /* a boundary string */
          $randomVal = md5(time());
          $mimeBoundary = "==Multipart_Boundary_x{$randomVal}x";

          /* Header for File Attachment */
          $headers .= "\nMIME-Version: 1.0\n";
          $headers .= "Content-Type: multipart/mixed;\n" ;
          $headers .= " boundary=\"{$mimeBoundary}\"";

          /* Multipart Boundary above message */
          $email_body = "This is a multi-part message in MIME format.\n\n" .
          "--{$mimeBoundary}\n" .
          "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
          "Content-Transfer-Encoding: 7bit\n\n" .
          $email_body . "\n\n";

          /* Encoding file data */
          $data1 = chunk_split(base64_encode($data1));
          $data2 = chunk_split(base64_encode($data2));
          $data3 = chunk_split(base64_encode($data3));
          $data4 = chunk_split(base64_encode($data4));
          $data5 = chunk_split(base64_encode($data5));

          /* Adding attchment-file to message*/
          $email_body .= "--{$mimeBoundary}\n" .
          "Content-Type: {$fileType};\n" .
          " name=\"{$fileName1}\"\n" .
          "Content-Transfer-Encoding: base64\n\n" .
          $data1 . "\n\n" .
          "--{$mimeBoundary}--\n";

          $email_body .= "--{$mimeBoundary}\n" .
          "Content-Type: {$fileType};\n" .
          " name=\"{$fileName2}\"\n" .
          "Content-Transfer-Encoding: base64\n\n" .
          $data2 . "\n\n" .
          "--{$mimeBoundary}--\n";

          $email_body .= "--{$mimeBoundary}\n" .
          "Content-Type: {$fileType};\n" .
          " name=\"{$fileName3}\"\n" .
          "Content-Transfer-Encoding: base64\n\n" .
          $data3 . "\n\n" .
          "--{$mimeBoundary}--\n";

          $email_body .= "--{$mimeBoundary}\n" .
          "Content-Type: {$fileType};\n" .
          " name=\"{$fileName4}\"\n" .
          "Content-Transfer-Encoding: base64\n\n" .
          $data4 . "\n\n" .
          "--{$mimeBoundary}--\n";

          $email_body .= "--{$mimeBoundary}\n" .
          "Content-Type: {$fileType};\n" .
          " name=\"{$fileName5}\"\n" .
          "Content-Transfer-Encoding: base64\n\n" .
          $data5 . "\n\n" .
          "--{$mimeBoundary}--\n";
    }
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;
    }
}

if(IsInjected($MOemail))
{
    echo "Bad email value!";
    exit;
}
@mail($to,$email_subject,$email_body,$headers);
header("Location: thank-you.html");

?>