gpt4 book ai didi

php - 我如何使用 Zend_Mail 发送附件?

转载 作者:可可西里 更新时间:2023-10-31 23:06:00 27 4
gpt4 key购买 nike

<?php

$message=$_POST['feedback'];
$attachments=$_POST['file'];
$subject=$_POST['subject'];
$tosend=$_POST['to'];
$tocc=$_POST['cc'];

$mail = new Zend_Mail();

$mail->setFrom('user@example.com','Admin');
$mail->addTo($tosend, 'Some Recipient');
$mail->addCc($tocc);

$mail->setType(Zend_Mime::MULTIPART_RELATED);
$mail->setSubject($subject);
$mail->setBodyHtml($message);

$attachments = $mail->createAttachment(file_get_contents($attachments));

$attachments->type = '.txt';
$attachments->filename = "";

$mail->send($transport);
?>

使用此代码我无法打开文件,它只使用文件名而不是打开附件的完整路径,当我单击打开附件时出现无法打开流的错误。

并且此代码与抄送密件抄送等其他功能配合使用时效果很好

最佳答案

$mail = new Zend_Mail();
$mail->setBodyHtml("description");
$mail->setFrom('id', 'name');
$mail->addTo(email, name);
$mail->setSubject(subject);

$content = file_get_contents("path to pdf file"); // e.g. ("attachment/abc.pdf")
$attachment = new Zend_Mime_Part($content);
$attachment->type = 'application/pdf';
$attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Zend_Mime::ENCODING_BASE64;
$attachment->filename = 'filename.pdf'; // name of file

$mail->addAttachment($attachment);

$mail->send();

关于php - 我如何使用 Zend_Mail 发送附件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20211314/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com