0

我在函数中有下面的代码..但是它从不将附件添加到电子邮件中。电子邮件很好,但没有附件。

但是,如果我从函数中删除代码并向其中添加一个单独的文件(没有函数部分)并且在同一目录中它可以正常工作。

为什么在函数中不添加附件?

function resendOrder()
{
    //global $siteEmailFrom, $siteEmailName, $dir;
    require_once('OrderMailer/class.phpmailer.php');// need this to send email

    $mail = new PHPMailer();
    // Now you only need to add the necessary stuff

    // HTML body

    $body = "Testing";

    // And the absolute required configurations for sending HTML with attachement
    $mail->From      = "mark@******.co.uk"; 
    $mail->AddAddress("mark@******.co.uk", "My-webpage Website");
    $mail->Subject = "test for phpmailer-3";
    $mail->MsgHTML($body);

    $mail->AddAttachment("ploxy.jpg");

    if(!$mail->Send()) {
        echo "There was an error sending the message";
        exit;
    }
    else{
        echo "Message was sent successfully";
    }
}
4

1 回答 1

0

不能引用附件名称“ploxy.jpg”,即:不能引用文件名。

你必须参考临时文件名,你可以做类似的事情

$_FILES['ploxy']['tmp_name']; // temp_name can be anything

或者更准确地说:

$filePath = "../images/"; // Path to image, can be the empty string.
$ploxy = $_FILES['ploxy']['tmp_name'];
$mail->AddAttachment($filePath, $ploxy);

基本上:您必须先将文件上传到脚本,然后才能发送;http://php.net/manual/en/features.file-upload.php

于 2013-04-15T11:47:33.730 回答