我想使用生成的附件(不是服务器上的文件)发送一封带有 PHP 的电子邮件,我对语法很好奇。
<?php
@require_once "Mail.php";
$from = "foo@me.com>";
$to = "blah@me.com>";
$subject = "Hi!";
$body = "Attached is the file\n\n";
$attachment = header( 'Content-Type: text/csv' );
$attachment = $attachment.header( 'Content-Disposition: attachment;filename=example.csv');
$attachment = 'transactionid,valid,fname,lname,email,studentid,status
"654","1","First Name","Last Name","Email@me.com","1000000"';
$body = $body.$attachment;
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = @Mail::factory('smtp', array('host' => $host,
'port' => $port,
'auth' => true,
'username' => $mail_username,
'password' => $mail_password));
$mail = @$smtp->send($to, $headers, $body);
if (@PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
编辑:请注意,我知道有很多在电子邮件中附加来自服务器的文件的示例,但我问的是如何将生成的 csv 文件(不在服务器上)附加到电子邮件中。