2012-06-27 47 views
2

您好我有問題,我已經使附件輸入簡單的形式,我想通過郵件發送這個附件到我的郵箱,但我總是看到錯誤附加文件isn;噸在文件系統上找到。PHPmailer和附件的形式 - 不發送

這是在PHP代碼:

<? 
    require('phpmailer/phpmailer.inc.php'); 

    $mail = new PHPMailer(); 

    $mail->From= $_POST['email']; 
    $mail->FromName= $_POST['contact']; 
    $mail->Sender= $_POST['email']; 
    $mail->AddReplyTo("xxxx", "Porozumienie"); 

    $mail->AddAddress("xxxxx"); 
    $mail->Subject = "Your invoice"; 

    $mail->IsHTML(false); 

    $plik_tmp = $_FILES[contr][tmp_name]; 
    $plik_nazwa = $_FILES[contr][name]; 
    $plik_rozmiar = $_FILES[contr][size]; 

    $target_path = "uploads/"; 

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

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

    $mail->AddAttachment(basename($target_path)); 

    $mail->Body = "Please find your invoice attached."; 
    if(!$mail->Send()) 
    { 
     echo "Error sending"; 
    } 
    else 
    { 
     echo "Letter is sent"; 
     unlink($target_path); 
    } 
?> 

什麼,我做錯了什麼?

+0

在require('phpmailer/phpmailer.inc.php')中檢查你的路徑。如果你的文件在其他文件夾中,那麼你應該寫require('../ phpmailer/phpmailer.inc.php')。 – Dhruvisha

回答

0

@arclite:因爲您正在獲取附件未找到錯誤。 檢查您的上傳文件夾權限,如果不是,請將其設置爲可寫。

@pari:由於他使用「require」,如果所需文件沒有退出,php會拋出一個錯誤。所以它不會是一個問題。

+0

我添加了chmod 777上傳/文件夾和即時獲取錯誤,而發送圖像我得到這個'Array ( [name] => map_point.png [type] => image/png [tmp_name] =>/tmp/php2n1DzO [錯誤] => 0 [尺寸] => 1380 ) 文件map_point.png已上載, 郵件錯誤 描述: 找不到上filesystem' – arclite

+0

文件map_point.png map_point.png文件在該文件夾中 – arclite