[英]How to create an XML file in PHP then send it as attachment via email
我可以這樣做,但是我不確定是否必須在服務器上創建文件然后將其附加,還是可以僅創建一個不駐留在服務器上的臨時文件而仍將其作為附件發送?
謝謝!
使用開源Swift Mailer庫http://swiftmailer.org/ ,您可以使用以下代碼創建不在服務器上的臨時文件:
<?php
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/NativeMail.php";
$swift =& new Swift(new Swift_Connection_NativeMail());
$message =& new Swift_Message("My subject");
$message->attach(new Swift_Message_Part("I have attached a file to this message!"));
$message->attach(new Swift_Message_Attachment(
'<xml>Whateveryouwant</xml>', "file.xml", "application/xml"));
$swift->send($message, "my-friend@host.tld", "me@my-domain.tld");
(示例代碼取自http://swiftmailer.org/wikidocs/v3/tutorials/attachments )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.