添加附件以在Yii中发送邮件

时间:2014-03-27 08:05:14

标签: php yii

我是Yii的新手。我正在使用YiiMail扩展程序发送邮件。我可以发送邮件但无法发送附件。

我有以下代码,但现在知道“tempName”到底意味着什么?

myController的 -

$uploadedFile = CUploadedFile::getInstanceByName('filename'); // get the CUploadedFile
$uploadedFileName = $uploadedFile->tempName; // will be something like 'myfile.jpg'
$swiftAttachment = Swift_Attachment::fromPath($uploadedFile); // create a Swift Attachment
$this->email->attach($swiftAttachment); // now attach the correct type

1 个答案:

答案 0 :(得分:2)

如果您上传文件(例如c:\path\file\myfile.jpg),则if临时存储在具有临时名称的临时文件夹中的服务器上(例如/tmp/zxhjkqwf.tmp)。 CUploadedFile包装了访问和操作文件所需的所有函数。 因此tempname将成为服务器上文件的路径。 我想你应该尝试改变你的代码lioke this:

$uploadedFile = CUploadedFile::getInstanceByName('filename'); // get the CUploadedFile
$uploadedFileName = $uploadedFile->tempName; // will be something like 'myfile.jpg'
$swiftAttachment = Swift_Attachment::fromPath($uploadedFileName); // create a Swift Attachment from the temporary file
$this->email->attach($swiftAttachment); // now attach the correct type

查看Documentation

中的更多信息
相关问题