2

嗨,我有一个问题,我用附件输入制作了简单的表格,我想通过邮件将此附件发送到我的邮箱,但我总是看到附件文件未在文件系统上找到的错误。

这是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);
    } 
?>

我做错了什么?

4

1 回答 1

0

@arclite:由于您收到未找到附件的错误。检查您的上传文件夹权限,如果没有,则使其可写。

@pari:由于他使用的是“require”,因此如果所需文件不退出,php 将抛出错误。所以这不可能是一个问题。

于 2012-06-27T07:49:20.063 回答