2015-06-08 30 views
1

我有一個奇怪的問題,我使用PHPMailer發送一些附件的電子郵件。使用jQuery將附件上傳到表單,該表單工作正常,文件上傳。當我使用IE和Firefox時,發送的電子郵件沒有問題,但是當我使用Google Chrome時,我收到錯誤消息「Could Not Instantiate Mail Funcition」,我認爲這很奇怪。無法實例化郵件功能 - PHPMailer - 附件 - 只有谷歌瀏覽器

但是,當我刪除腳本的附件部分時,電子郵件在所有瀏覽器中都發送正常,因此我會假定PHPMailer試圖將文件附加到窗體時發生問題,因此我運行了一些測試以確保文件肯定會上傳並確實存在,並且這些測試恢復正常。

<?php 
$attachment_location = "files/"; 
$attachments = $_POST["files"]; 
require_once('../includes/PHPMailer/class.phpmailer.php'); 
$mail = new PHPMailer(true); 
try { 
$mail ->isMail(); 
$body = '  
<html> 
    <head> 
     <title>New Account Application Submitted</title> 
     <style type="text/css"> 
      body { 
       font-family: Arial; 
      } 
     </style> 
    </head> 
    <body> 
     <h1>New Account Application Submitted</h1> 
     <p>A user completed the account application form please see the attached documents</p> 
     <p>Thank You</p> 
    </body> 
</html> 
     '; 
$mail->SetFrom('[email protected]'); 
$address = "[email protected]"; 
$mail->AddAddress($address); 
$mail->Subject = "New Account Application Submitted"; 
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; 
$mail->MsgHTML($body); 
foreach($attachments as $attachment){ 
    if(file_exists($attachment_location . $attachment)){ 
     $mail->AddAttachment($attachment_location . $attachment); 
    }else{ 
     echo "File does not exist " . $attachment_location . $attachment . "<br>"; 
    } 
} 
$mail->Send(); 
} catch (phpmailerException $e) { 
    echo $e->errorMessage(); 
} catch (Exception $e) { 
    echo $e->getMessage(); 
} 
foreach($attachments as $attachment){ 
    unlink($attachment_location . $attachment); 
} 
echo "Your application has been received<br> a member of our team will be in contact with you shortly"; 
?> 

我希望有人能提前

亞當

回答

0

你沒有正確處理您的文件上傳在這個問題上提供一些線索

感謝。閱讀PHP file uploading docs,並按照PHPMailer提供的send file upload example進行操作。

確保您的表單具有enctype="multipart/form-data"屬性並且包含<input type="hidden" name="MAX_FILE_SIZE" value="30000" />輸入標記。

然後使用move_uploaded_file並且不要嘗試直接使用$_FILES的內容。

+0

謝謝你的迴應!我已經查看了你說的,我正在使用一個jQuery插件來處理BlueImp上傳的文件https://github.com/blueimp/jQuery-File-Upload,它有一個內置的函數,在文件有完全上傳,我搞砸了,只允許表單提交一次完全完成,並在Google Chrome中實現了這一招,謝謝 –