繁体   English   中英

PHP Form邮件附件

[英]PHP Form mail attachments

我正在尝试修复我正在处理的表格之一。 我不是开发人员,因此还有其他问题,即我的代码与那里的代码有很大不同,哪里没有真正的帮助。

我正在查看的基本功能是我有一个带有多个文件上传字段的表单。

这是基本的前端代码:

 <form action="mailer.php" method="post" name="mainform" enctype="multipart/form-data">
    <table width="500" border="0" cellpadding="5" cellspacing="5">
       <tr>
        <th>Name:* </th>
        <td><input name="FName" type="text"></td>
    </tr>
    <tr>
    <tr>
        <th>Email:* </th>
        <td><input name="YEmail" type="text"></td>
    </tr>
    <tr>
        <th>Side 1 Text:* </th>
        <td><input name="S1Text" type="text"></td>
    </tr>
 <tr>
        <th>Side 2 Text:* </th>
        <td><input name="S2Text" type="text"></td>
    </tr>
    <tr>
        <th>Poker Chip:* </th>
        <td><select name="PokerChip" id="PokerChip">
        <option value="8 Stripe Inlay">8 Stripe Inlay</option>
        <option value="Hot Stamp Chip">Hot Stamp Chip</option>
        <option value="6 Stripe Direct Print">6 Stripe Direct Print</option>
        <option value="Clean Slate Ceramic">Clean Slate Ceramic</option>
        <option value="6 Stripe Deluxe Print">6 Stripe Deluxe Print</option>
        <option value="Dice Full Color Print">Dice Full Color Print</option>
        <option value="High Roller Rectangle">High Roller Rectangle</option>
        <option value="Tri-Color Clay">Tri-Color Clay</option>
        <option value="Pro Clay Hot Stamp">Pro Clay Hot Stamp</option>
            </select>
        </td>
    </tr>
    <tr>
        <th>Comments: </th>
        <td><textarea name="SpecialInstructions" cols="20" rows="4" id="SpecialInstructions"></textarea></td>
    </tr>
    <tr>
      <th>Upload File 1:</th>
      <td><input name="attachment" type="file">(File must be 10 MB or less)</td>
    </tr>
     <tr>
      <th>Upload File 2:</th>
      <td><input name="attachment2" type="file">(File must be 10 MB or less)</td>
    </tr>
    <tr>
        <td colspan="2" style="text-align:center;"><input type="submit" name="Submit" value="Send"></td>
    </tr>
    </table>
    </form>

现在,我的mailer.php文件中的代码是:

 <?php

$to_Email = "xxx"; //Replace with recipient email address
$subject = 'Virtual Proof Request Email';
$fromEmail = $_POST['YEmail']; 
$fromName = $_POST['FName']; 
$sidetext1 = $_POST['S1Text']; 
$sidetext2 = $_POST['S2Text']; 
$pokerchip = $_POST['PokerChip']; 
$specialinstructions = $_POST['SpecialInstructions'];
$message = "Name: $fromName\n\nEmail: $fromEmail\n\nSide Text 1: $sidetext1\n\nSide Text 2: $sidetext2\n\nPoker Chip: $pokerchip\n\nSpecial Instructions: $specialinstructions"; 



/* GET File Variables */ 
$tmpName = $_FILES['attachment']['tmp_name']; 
$fileType = $_FILES['attachment']['type']; 
$fileName = $_FILES['attachment']['name']; 

$tmpName2 = $_FILES['attachment2']['tmp_name']; 
$fileType2 = $_FILES['attachment2']['type']; 
$fileName2 = $_FILES['attachment2']['name']; 

/* Start of headers */ 
$headers = "From: $fromName $fromEmail"; 


if (file($tmpName)) { 
  /* Reading file ('rb' = read binary)  */
  $file = fopen($tmpName,'rb'); 
  $data = fread($file,filesize($tmpName)); 
  fclose($file); 


  /* 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 */
  $message = "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" . 
  $message . "\n\n"; 


  /* Encoding file data */
  $data = chunk_split(base64_encode($data)); 

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


} 

$flgchk = mail ("$to_Email", "$subject", "$message", "$headers"); 

if($flgchk){
  header ('Location: index.php?route=information/information&information_id=8');
 }
else{
  header ('Location: index.php?route=information/information&information_id=9');
}
?>

问题是我只收到1个附件,而不是2个。

我不是程序员..任何人都可以尽早对此进行指导吗?

万分感谢

永远不会处理文件2。

if只在这里检查文件1:if(file($ tmpName))

您需要复制整个块,并将$ tmpName更改为$ tmpName2。 标头中的更改只需完成一次,因此您可以在复制的块中将其删除。

希望能使您走上正确的道路。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM