Sending email with local attachment

Good evening,

I’m a total newbie to Yii, and I try to use a form in HTML to setup an email with an attachment and send it to a specific email address. I’m using yiimail which is working fine, except for the attachment. I’m using an input file in HTML that returns only the filename, not the complete path.

I’ve searched on the net and found it is a security measure and I found no way to bypass it.

Here’s the code in the SiteController. It works, except for the attachment part.

$message = new YiiMailMessage;

$bodyMessage = '<html>'; //<head><meta content="text/html; charset=utf-8" http-equiv="content-type"></head><body>';

$bodyMessage .= 'Nom: ' . $model->familyName . '<br>Prénom: ' . $model->firstName . '<br>Téléphone: ' . $model->phoneNumber;

$bodyMessage .= '<br><br>Poste: ' . $model->subject . '<br><br>Présentation: ' . $model->body . '</html>';


$message->subject = '[Candidature] Poste: ' . $model->subject;


$message->from = $model->email;

$uploadedFile = CUploadedFile::getInstanceByName($model->cvDocument);

$uploadedFileName = $uploadedFile->tempName;

$swiftAttachment = Swift_Attachment::fromPath($uploadedFileName);


Here’s part of the code in the view, with the input file:


	<label class="cvLabel" for="EmploiForm_cvDocument">C.V.

		<span class="cvTypes">(.pdf .doc .docx)</span>


	<input type="hidden" name="chemin" id="chemin" value="">

	<input type="file" class="required file" name="EmploiForm[cvDocument]" id="EmploiForm_cvDocument"/>


<p class="submitBtn">

	<input type="submit" class="submit" name="envoyer" value="Envoyer"/>


Here’s my model:

	class EmploiForm extends CFormModel


		public $firstName;

		public $familyName;

		public $email;

		public $subject;

		public $body;

		public $phoneNumber;

		public $cvDocument;


		 * Declares the validation rules.


		public function rules()


			return array(

				// name, email, subject and body are required

				array('firstName, familyName, email, subject, body, phoneNumber, cvDocument', 'required'),

				// email has to be a valid email address

				array('email', 'email'),

				// verifyCode needs to be entered correctly

				//array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),




		 * Declares customized attribute labels.

		 * If not declared here, an attribute would have a label that is

		 * the same as its name with the first letter in upper case.


		public function attributeLabels()


			return array(






				'phoneNumber'=>'Numéro de téléphone',

				'cvDocument'=>'Curriculum vitae',

				//'verifyCode'=>'Verification Code',




I confirm I do not need to keep the file, only to send it by email. In short, a person is selecting his CV in the input file, type his message, click on send and an email is sent with the description, name, and copy of the CV to a specific address.

Any help or suggestions is welcome, because I’m desperate. Thanks!

Nobody can’t help me?

Do you manage to do it?