【问题标题】:Syntax for sending a email header attachment [duplicate]发送电子邮件标题附件的语法 [重复]
【发布时间】: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 给我看一个副本,我找不到任何类似的问题...所有问题都是关于从服务器附加文件...不是生成的文件...请阅读完整问题
  • 所以。您尝试过哪些搜索?是时候查看手册了吗?

标签: php email pear


【解决方案1】:

How to send emails with PHP using the PEAR Mail package with attachment开头

然后替换如下:

if ($mime->addAttachment($file,'application/pdf')){

$file =  'transactionid,valid,fname,lname,email,studentid,status
            "654","1","First Name","Last Name","Email@me.com","1000000"';
if ($mime->addAttachment($file,'text/csv', 'example.csv', false)){

参见http://pear.php.net/manual/en/package.mail.mail-mime.addattachment.php的文档

【讨论】:

  • 谢谢!这正是我想要的!
猜你喜欢
  • 2015-10-30
  • 2012-11-28
  • 1970-01-01
  • 2020-09-19
  • 1970-01-01
  • 2017-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多