如何使用PHPMailer将临时PHP文件作为附件发送?

时间:2013-05-29 09:57:18

标签: php phpmailer email-attachments

我正在尝试将我的PHP代码创建的临时文件作为电子邮件附件发送。

我正在使用PHPMailer - 当我尝试将附件添加到物理文件时这可以正常工作..我不确定我需要做什么来附加临时文件..

以下是一些代码:

require_once("class/BuildPass.php");
require_once("../../Utilities/PHPMailer/class.phpmailer.php");

// Prepare email 
$mail = new PHPMailer();
$mail->SetFrom("address@mycompany.com", "My Company");
$mail->AddAddress($email, $name);
$mail->Subject = "Here's your email with file attachment";
$mail->CharSet="UTF-8";

// Retrieve the email template required
$message = file_get_contents('pass/email_templates/Event200613.html');  // HTML Mail template
// Replace the % with the actual information
$message = str_replace('%name%', $name, $message);
$message = str_replace('%email%', $email, $message);
// Add embedded images
$mail->AddEmbeddedImage("Images/strip.png", "strip");
$mail->AddEmbeddedImage("Images/logo5787924_md.jpg", "Company_logo");

//generate a new pass
$newPass = BuildPass::createPass($name, $email, $barcode, $error);  // This function creates an Apple Passbook file with .pkpass extension ...

$mail->MsgHTML($message);

$mail->Send();

这段代码对我来说很好..它发送一封HTML电子邮件,其图像嵌入正确..(注意 - $ name和$ email在输入表单中定义)..

现在我想附加临时文件$ newPass。 我不能简单地使用

$mail->AddAttachment($newPass);  // This crashes

我认为我需要创建一个带有已定义路径名的临时文件,然后添加此附件 - 但是我无法找到有关如何操作的正确信息..

非常感谢任何帮助..

安德鲁

var_dump($newPass);

object(BuildPass)#2 (7) { ["keyPath":"BuildPass":private]=> string(89) "/mnt/stor08-wc1-ord1/738827/dev.myserver.com/web/content/path/pass" ["sourcePath":"BuildPass":private]=> string(96) "/mnt/stor08-wc1-ord1/738827/dev.myserver.com/web/content/path/pass/source" ["workFolder":"Pass":private]=> string(18) "/tmp/51a5d3795c59e" ["ID":"Pass":private]=> string(13) "blahblah" ["content"]=> array(14) { lots of stuff } } } } ["passBundleFile"]=> string(39) "/tmp/51a5d3795c59e/51a5d3795c59e.pkpass" }

0 个答案:

没有答案