嗨,我一直在试图弄清楚如何将图像附加到要发送给联系表单用户的电子邮件中 . 它现在所做的只是将图像的文件名附加到电子邮件而不是实际图像:

站点控制器:

public function actionContact(){

$model=new ContactForm;
    if(isset($_POST['ContactForm']))
    {   
        $model->attributes=$_POST['ContactForm'];
        if($model->validate())
        {
            $model->image=CUploadedFile::getInstance($model,'image');
            $model->image->saveAs('/tmp/emailScap');

            $headers="From: {$model->email}\r\nReply-To: {$model->email}";
            mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$model->image,$headers);
            Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
            $this->refresh();
        }
    }
    $this->render('contact',array('model'=>$model));
}

模型:

class ContactForm扩展了CFormModel

{

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'=>'{attribute} 不可以為空。'),
        // email has to be a valid email address
        array('email', 'email', 'message'=>'請填寫正確的{attribute}。'),
        // verifyCode needs to be entered correctly
        array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements(), 'message'=>'認證碼不可以為空。'),
        // Image
        array('image', 'file', 'allowEmpty'=>true, 'safe'=>true, 'types'=>'jpg, jpeg, gif, png'),
    );
}