2

データを入力し、ファイルを添付してメールで送信できるフォームがあります。私の携帯電話、Safari、Firefox、Chrome では動作しますが、IE では動作しません。(phpページに投稿することすらありません。)

HTML:

<form method="post" id="mainForm" enctype="multipart/form-data" action="email.php">
        <span class="hide" id="status"></span>
        <div class="rowElem">
            <label for="name">Member Name:</label>
            <div class="formRight">
                <input id="name" type="text" name="name" required placeholder="John Doe" />
            </div>
        </div>
        <div class="rowElem">
            <label for="email">Member Email: </label>
            <div class="formRight">
                <input id="email" type="email" name="email"  required placeholder="john.doe@email.com" />
            </div>
        </div>
        <div class="rowElem">
            <label for="subject">Subject: </label>
            <div class="formRight">
                <input id="subject" type="text" name="subject"  required placeholder="Phone Call Follow Up"/>
            </div>
        </div>
        <div class="rowElem">
            <label for="message">Message: </label>
            <div class="formRight">
                <textarea id="message" name="message"  required ></textarea> 
            </div>
        </div>
        <div class="rowElem">
            <label for="attachment">Attachment: </label>
            <div class="formRight">
                <input id="attachment" type="file" name="attachment"/>
            </div>
        </div>
        <div class="rowElem">
            <button class="submit">Send Email</button>
            <button class="reset" onClick="resetForm()">Reset Form</button>
        </div>
    </form>

PHP:

<?php 
    $membername = $_POST['name'];
    $email = $_POST['email'];
    $content = $_POST['message'];
    $subject = $_POST['subject'];

    $maxTotalAttachments=5097152; //Maximum of 2 MB total attachments, in bytes
    $boundary_text = uniqid();
    $boundary = "--".$boundary_text."\r\n";
    $boundary_last = "--".$boundary_text."--\r\n";

     //Build up the list of attachments, 
    //getting a total size and adding boundaries as needed
     $emailAttachments = "";
     $totalAttachmentSize = 0;
     foreach ($_FILES as $file) {
        //In case some file inputs are left blank - ignore them
        if ($file['error'] == 0 && $file['size'] > 0){
             $fileContents = file_get_contents($file['tmp_name']);
             $totalAttachmentSize += $file['size']; //size in bytes
             $emailAttachments .= "Content-Type: " 
            .$file['type'] . "; name=\"" . basename($file['name']) . "\"\r\n"
            ."Content-Transfer-Encoding: base64\r\n"
            ."Content-disposition: attachment; filename=\"" 
            .basename($file['name']) . "\"\r\n"
            ."\r\n"
            //Convert the file's binary info into ASCII characters
            .chunk_split(base64_encode($fileContents))
             .$boundary;
         }
    }
  //Now all the attachment data is ready to insert into the email body.
  //If the file was too big for PHP, it may show as having 0 size
  if ($totalAttachmentSize == 0) {
    echo "Message not sent. Either no file was attached, or it was bigger than PHP is configured to accept.  ".basename($file['name']);
}
  //Now make sure it doesn't exceed this function's specified limit:
  else if ($totalAttachmentSize>$maxTotalAttachments) {
    echo "Message not sent. Total attachments can't exceed " .  $maxTotalAttachments . " bytes.";
  }
  //Everything is OK - let's build up the email
  else {  
    $to = $email;
    $subject = $subject;
    $from = "do-not-reply@someemail.com";
    $headers = "From: ".$from." \r\n";
    $headers .= 'Bcc: someone@someemail.com' . "\r\n";
    $headers .=     "MIME-Version: 1.0\r\n"
    ."Content-Type: multipart/mixed; boundary=\"$boundary_text\"" . "\r\n";  
    $message .="If you can see this, your email client "
    ."doesn't accept MIME types!\r\n"
    .$boundary;

    $message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
    ."Content-Transfer-Encoding: 7bit\r\n\r\n" 
    //Inert the HTML message body you passed into this function
    ."Hello ".$membername."<br><br>" . $content . "<br><br> Please do not reply to this message. Replies to this message are routed to an unmonitored mailbox. If you have questions please go to... You may also call us at .... Thank you. " . "\r\n";

    //Insert the attachment information we built up above.
    //Each of those attachments ends in a regular boundary string   

    $message .= $emailAttachments

    //This section ends in a terminating boundary string - meaning
    //"that was the last section, we're done"
    .$boundary_last;

    if(mail($to,$subject,$message,$headers)){
     echo 'some html goes here.';  
    } 
    else {
      echo 'Error - mail not sent.';
    }
  }    

?>
4

2 に答える 2

2

IE は、現在フォームにあるものなど、送信する手段として<button>withoutを使用しているため、フォームを実行していません。type="submit"

<button class="submit">Send Email</button> 

次のような入力タイプを使用できます。

<input type="submit" name="submit" value="Send Email">

または、次のようなプレゼント ボタンに追加type="submit"します。

<button class="submit" type="submit">Send Email</button>

私はそれとIEをテストしましたが、フォームを含めずに「ボタン」として送信したくありませんでしたtype="submit"

別の問題はハンドラーにありました。ヘッダー情報がメッセージ本文領域自体に漏洩していたため、以下の回答で添付ファイル ハンドラーの 1 つを使用しました。

たとえば、漏れのあるメッセージ本文の部分的なコピーを次に示します。

こんにちはフレッド

メッセージのテスト

このメッセージには返信しないでください。このメッセージへの返信は、監視されていないメールボックスにルーティングされます。ご不明な点がございましたら、... にアクセスしてください。また、... までお電話いただくこともできます。コンテンツ タイプ: 画像/jpeg; name="test_image.jpg" Content-Transfer-Encoding: base64 Content-disposition: attachment; filename="test_image.jpg" LzlqLzRBQVFTa1pKUmdBQkFnQUFaQUJrQUFELzdBQVJSSFZqYTNrQUFRQUVB......................................

次のフォームとハンドラーを使用すると、IE 7 と FF 24 の両方で添付ファイル付きの電子メールを正常に送信できました。

HTMLフォーム

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="sendmail_attach.php" method="post" name="form1" enctype="multipart/form-data">
<table width="343" border="1">

<tr>
<td>Name</td>
<td><input name="txtFormName" type="text"></td>
</tr>
<tr>
<tr>
<td>Form Email</td>
<td><input name="txtFormEmail" type="text"></td>
</tr>

<tr>
<td>Message:</td>
<td><textarea name="txtDescription" cols="30" rows="4" id="txtDescription"></textarea></td>
</tr>

<tr>
<td>Attachment</td>
<td><input name="fileAttach" type="file"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Send Message"></td>
</tr>
</table>
</form>
</body>
</html>

PHP ハンドラー (sendmail_attach.php)

<?php
$strTo = "email@example.com";
$strSubject = "Email attach subject";
$strMessage = nl2br($_POST["txtDescription"]);

//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));

$strHeader = "";
$strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";

$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";

$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";

//*** Attachment ***//
if($_FILES["fileAttach"]["name"] != "")
{
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}

$flgSend = @mail($strTo,$strSubject,null,$strHeader);  // @ = No Show Error //

if($flgSend)
{
echo "Mail send completed.";
}
else
{
echo "Cannot send mail.";
}
?>
于 2013-09-18T03:35:19.747 に答える
0

このスタック オーバーフローの質問の回答を確認してください: PHP フォームが Internet Explorer で機能しない

フォーム構造の何かかもしれません。

于 2013-09-18T02:24:47.357 に答える