嗨我試圖做一個表格,可以發送電子郵件使用yii/mail
,問題是我只能發送一種形式成爲文本正文,我已經編碼這樣的模型如何發送多個settextbody yii2發送郵件
class CareerForm extends Model
{
public $name;
public $email;
public $subject;
public $body;
public $verifyCode;
public $gender;
public function rules()
{
return [
[['name', 'email', 'subject', 'body','gender'], 'required'],
['email', 'email'],
['verifyCode', 'captcha'],
];
}
public function career($email)
{
if ($this->validate()) {
Yii::$app->mailer->compose()
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
return true;
}
return false;
}
}
如何使用多個參數來
->setTextBody($this->body)
像
->setTextBody($this->body,$this->gender)
BEC在我看來,我有幾個text input
和radio list
作爲電子郵件發送,我該怎麼做?
我的短信預期將是這樣的:
name
gender
variable 1
variable 2
variable n
摘要 編輯=兩者的答案是正確的,但我用
public function career($email)
{
if ($this->validate()) {
Yii::$app->mailer->compose('filename.html' ,[
'email' => $this->email,
'name' => $this->name,
])
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject('career')
->send();
return true;
}
return false;}
感謝安高爾·加和PRATIK Karmakar
準備電子郵件的身體befroe調用 - > setTextBody($ this-> body),然後設置爲$ this-> body –
如果您說先準備好電子郵件正文,那麼如何將2個變量(body和gender)合併爲一個變量(body)? –
正文是一個字符串。試試這個 $ this-> body。= $ this-> gender; –