PHPmailer和附件表单 - 不发送

时间:2012-06-27 07:36:57

标签: php phpmailer email-attachments

您好我有问题我已经使用附件输入制作了简单的表单,我想通过邮件将此附件发送到我的邮箱但是我总是看到附加文件的错误在文件系统上找不到。

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

我做错了什么?

1 个答案:

答案 0 :(得分:0)

@arclite:因为你找不到附件错误。 检查您的上传文件夹权限,如果没有,请将其设为可写。

@pari:由于他正在使用“require”,如果所需文件没有退出,php将抛出错误。所以这不是问题。

相关问题