【发布时间】:2012-11-12 18:28:02
【问题描述】:
可能重复:
How to send emails with PHP using the PEAR Mail package with attachment
我想使用生成的附件(不是服务器上的文件)发送一封带有 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 文件(不在服务器上)附加到电子邮件中。
【问题讨论】:
-
header()函数与文本处理/邮件无关。而.是连接运算符,不适用于方法调用。 -
@mario 这不是重复的,该示例显示从服务器上的文件附加...我如何使用生成的 cvs 字符串附加?
-
我们还有几百个副本。如果没有手册,请使用搜索功能。
-
@mari 给我看一个副本,我找不到任何类似的问题...所有问题都是关于从服务器附加文件...不是生成的文件...请阅读完整问题
-
所以。您尝试过哪些搜索?是时候查看手册了吗?