2013-12-19 23 views
1

我已經上傳的文件,現在我需要發送上傳的文件在郵件作爲attachment.Refer小提琴file upload。如何在郵寄此上傳作爲附件。如何使用jQuery發送上傳的文件在郵件作爲附件

HTML

<form id="myform" action="process-upload.php" method="post" enctype="multipart/form-data"> 

<input id="tele" type="file" name="filename"/> 
<br/> 
<input class="formbtn" type="submit" value="Upload" /> 

的jquery

$(文件)。就緒(函數(){

$('#myform').validate({ 
    rules: { 
     filename: { 
      required: true, 
      extension: "docx|rtf|doc|pdf" 
     } 
    }, 
    messages: { 
     filename: { 
      required: "Please upload resume", 
      extension: "Please upload valid file formats" 
     } 
    } 
}); 

});

PHP

<?php 
require("class.phpmailer.php"); 
$email = new PHPMailer(); 
$email->From  = '[email protected]'; 
$email->FromName = 'Name'; 
$email->Subject = 'Subject'; 
$email->Body  = 'Message Body'; 
$email->AddAddress('[email protected]'); 
$target_path = "uploads/"; 

$target_path = $target_path . basename($_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { 
    echo "The file ". basename($_FILES['uploadedfile']['name']). 
    " has been uploaded"; 
} else{ 
    echo "There was an error uploading the file, please try again!"; 
} 
$email->AddAttachment(basename($target_path . $_FILES['uploadedfile']['name'])); 


return $email->Send(); 
?> 
+0

郵件代碼在哪裏? –

+0

我沒有寫它yet.My本身的問題,只有如何發送此上傳的文件作爲附件 –

+0

不是很困難task.try谷歌it.visit的電子郵件一些鏈接[http://webcheatsheet.com/php /send_email_text_html_attachment.php],[http://php.net/manual/en/function.mail.php] –

回答

2

您可以使用PHP梅勒類爲。檢查下面的代碼。

$email = new PHPMailer(); 
$email->From  = '[email protected]'; 
$email->FromName = 'Name'; 
$email->Subject = 'Subject'; 
$email->Body  = 'Message Body'; 
$email->AddAddress('[email protected]'); 

$filetoattach = 'File path'; 

$email->AddAttachment($filetoattach , 'filename.doc'); 

return $email->Send(); 

你可以從這個鏈接下載PHP郵件類:PHPMailer

讓我知道如果您有任何查詢!

謝謝

+0

我對如何包括PHP郵件不知道。你可以在小提琴中解釋它嗎 –

+0

根本沒有任何硬件或智能工作,只需下載PHPMailer幷包含類文件,如下所示:** require_once('folderpath/class.phpmailer.php'); ** – Chandresh

+0

Hi請檢查更新後的code.mail功能對我不起作用 –

相關問題