title: Attach image to Yii contact form
body: <p>Hi I've been trying to figure out how to attach an image to an email to be sent to user of the contact form. All it does right now is literally attach the filename of the image to the email but not the actual image:</p>
  
  <p>Site Controller:</p>
  
  <p>public function actionContact()
      {</p>
  
  <pre><code>    $model=new ContactForm;
      if(isset($_POST['ContactForm']))
      {   
          $model-&gt;attributes=$_POST['ContactForm'];
          if($model-&gt;validate())
          {
              $model-&gt;image=CUploadedFile::getInstance($model,'image');
              $model-&gt;image-&gt;saveAs('/tmp/emailScap');
  
              $headers="From: {$model-&gt;email}\r\nReply-To: {$model-&gt;email}";
              mail(Yii::app()-&gt;params['adminEmail'],$model-&gt;subject,$model-&gt;body,$model-&gt;image,$headers);
              Yii::app()-&gt;user-&gt;setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
              $this-&gt;refresh();
          }
      }
      $this-&gt;render('contact',array('model'=&gt;$model));
  }
  </code></pre>
  
  <p>Model:</p>
  
  <p>class ContactForm extends CFormModel</p>
  
  <p>{</p>
  
  <pre><code>public $name;
  public $email;
  public $subject;
  public $body;
  public $image;
  public $verifyCode;
  
  /**
   * Declares the validation rules.
   */
  public function rules()
  {
      return array(
          // name, email, subject and body are required
          array('name, email, subject, body', 'required', 'message'=&gt;'{attribute} 不可以為空。'),
          // email has to be a valid email address
          array('email', 'email', 'message'=&gt;'請填寫正確的{attribute}。'),
          // verifyCode needs to be entered correctly
          array('verifyCode', 'captcha', 'allowEmpty'=&gt;!CCaptcha::checkRequirements(), 'message'=&gt;'認證碼不可以為空。'),
          // Image
          array('image', 'file', 'allowEmpty'=&gt;true, 'safe'=&gt;true, 'types'=&gt;'jpg, jpeg, gif, png'),
      );
  }
  </code></pre>