Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Phpmailer PHP编译器代码在功能内时不工作_Phpmailer_Php - Fatal编程技术网

Phpmailer PHP编译器代码在功能内时不工作

Phpmailer PHP编译器代码在功能内时不工作,phpmailer,php,Phpmailer,Php,我在函数中有下面的代码。。但是,它从不将附件添加到电子邮件中。这封邮件可以通过,但没有附件 但是,如果我从函数中删除代码并添加一个单独的文件(没有函数部分)到同一个目录中,它就可以正常工作 为什么在函数中不添加附件 function resendOrder() { //global $siteEmailFrom, $siteEmailName, $dir; require_once('OrderMailer/class.phpmailer.php');// need this t

我在函数中有下面的代码。。但是,它从不将附件添加到电子邮件中。这封邮件可以通过,但没有附件

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

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

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";
    }
}

您不能引用附件“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);

基本上:您必须先将文件上载到脚本,然后才能发送它

好的,谢谢。不应该是:$filePath=“../images/”;/图像的路径,可以是空字符串$ploxy=$\u文件['ploxy.jpg']['tmp\u名称']$邮件->添加附件($filePath,$ploxy);不,文件扩展名不应该在那里。记住,如果有帮助就投票,如果解决了问题就接受。如果没有,那么我可以告诉你,如果你只是正确地用谷歌搜索,这个问题已经解决了很多次。