Swift邮件附件 [英] Swift mailer attachment
问题描述
我在yii中尝试了两次电子邮件扩展.
I have tried email extensions in yii twice.
1.YII-MAIL
2.PHP MAILER
现在,我想试用swift mailer.我已经从此处 http://swiftmailer.org/download下载了软件包并将其添加到YII的扩展程序文件夹中.
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.
在这里,我有一个表格,其中包含姓名,电子邮件,电话和附件字段.我将上载的文件保存到images文件夹下的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扩展用于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邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!