<?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);
?>使用这段代码我不能打开文件,它只接受文件名而不是整个路径来打开附件,当我点击打开附件时,它给出的错误是无法打开流。
这段代码可以很好地与cc、Bcc等其他特性协同工作。
发布于 2013-11-26 19:47:09
$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(); 发布于 2013-11-26 16:39:15
您需要使用$_FILES数组打开文件,而不是使用$_POST。$_POST只包含文件名,$_FILES包含实际文件。
请参阅http://php.net/manual/en/reserved.variables.files.php
此外,Zend_Mime_Part::type需要MIME类型,即$attachments->type需要是MIME类型。对于文本文件,这是text/plain。我也不认为你可以设置一个空的文件名。
发布于 2013-11-27 20:45:12
请试试这个,它会起作用的。
$file = "path of file";
$mail = new Zend_Mail();
$mail->setFrom("test@test.com", "test");
$mail->addTo("test1@test.com", "test user");
$mail->setSubject("file mail");
$mail->setBodyHtml("html");
$at = new Zend_Mime_Part(file_get_contents($file));
$at->type = mime_content_type($file);
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_BASE64;
$at->filename = basename($file);
$mail->addAttachment($at);
if($mail->send())
{
echo " sent";
}
else
{
echo "not sent";
}
?>https://stackoverflow.com/questions/20211314
复制相似问题