我将下面的代码放在一个函数中。但是,它从不将附件添加到电子邮件中。这封电子邮件通过得很好,但没有附件。
但是,如果我从函数中删除代码,并在同一目录中添加一个单独的文件(没有函数部分),它就可以正常工作。
为什么在函数中不添加附件?
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";
}
}发布于 2013-04-15 19:47:34
您不能引用附件"ploxy.jpg“的名称,即:您不能引用该文件的名称。
你必须引用临时文件名,你可以这样做
$_FILES['ploxy']['tmp_name']; // temp_name can be anythingOre更准确地说:
$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
https://stackoverflow.com/questions/16014224
复制相似问题