Swift mailer attachment(Swift 邮件附件)
问题描述
我在 yii 中尝试过两次电子邮件扩展.
I have tried email extensions in yii twice.
1.YII-MAIL
2.PHP MAILER
现在我想试试 swift mailer.我已经从这里下载了这个包 http://swiftmailer.org/download 并将其添加到 YII 中的 extensions 文件夹中.
Now i would like to try out swift mailer.I have downloaded the package from here http://swiftmailer.org/download and added it to the extensions folder in YII.
这里我有一个表单,其中包含姓名、电子邮件、电话和附件字段.我将上传的文件保存到图像文件夹下名为 resumes 的文件夹中,同时我正在发送一封邮件,其中包含所有详细信息以及上传的文件作为附件.但是在单击创建按钮时,我收到此错误
Here i have a form ,with fields for name,email,phone and an attachment. I am saving the file uploaded to a folder called resumes under images folder ,at the same time i am sending a mail with all details along with the uploaded file as an attachment .But on clicking create button i am getting this error
include(Swift_Message.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
这是我迄今为止尝试过的控制器操作
Here is the controller action i have tried so far
public function actionCreate()
{
$this->layout='static_inner';
$model=new LriCareer;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['LriCareer']))
{
$rnd = rand(0,9999);
$model->attributes=$_POST['LriCareer'];
if($uploadedFile=CUploadedFile::getInstance($model,'career_resume'))
{
$fileName = "{$rnd}-{$uploadedFile}"; // random number + file name
$model->career_resume = $fileName;
if($model->save())
{
$uploadedFile->saveAs(dirname(Yii::app()->basePath) . '/images/resumes/'.$fileName);
$message = new YiiMailMessage;
$first_name="hello";
$message->setBody($first_name);
$message->subject = 'My Subject';
$message->addTo('fazeela.ma@longriverinfotech.com');
$message->from = Yii::app()->params['adminEmail'];
$uploadedFile = CUploadedFile::getInstanceByName('fileupload'); // get the CUploadedFile
$uploadedFileName = $uploadedFile->tempName; // will be something like 'myfile.jpg'
$swiftAttachment = Swift_Attachment::fromPath($uploadedFileName);
$message->attach($swiftAttachment);
}
}
else
{
if($model->save())
$this->redirect(array('view','id'=>$model->career_id));
}}
$this->render('create',array(
'model'=>$model,
));
}
我在文件夹中没有看到 Swift_message.php.任何人都可以调查这个问题
I dont see Swift_message.php in the folder.Can any one out there can look into the problem
推荐答案
有一个 Swiftmailer Extension 用于 Yii 框架.我个人在几个项目中使用过,它很棒.
There is a Swiftmailer Extension for Yii Framework. I've personally used in a couple of projects and its awesome.
如何附加文件:
$message = new YiiMailMessage;
$message->setBody($first_name);
$message->subject = 'My Subject';
$message->addTo('my@domain.com');
$message->from = Yii::app()->params['adminEmail'];
$uploadedFileName = CUploadedFile::getInstance($model,'career_resume');
$uploadedFileName = $uploadedFile->tempName; // will be something like 'myfile.jpg'
$swiftAttachment = Swift_Attachment::fromPath($uploadedFileName);
$message->attach($swiftAttachment);
这篇关于Swift 邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Swift 邮件附件


- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01