我正在尝试将我的 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" }