我在函数中有以下代码..但它永远不会将附件添加到电子邮件中。电子邮件很好但没有附件。
但是,如果我从函数中删除代码并添加一个单独的文件(没有函数部分)并且在同一目录中它可以正常工作。
为什么在函数中没有添加附件?
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";
}
}
答案 0 :(得分: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