Hi I've trying to make a form that can send email using yii/mail
, the problem is I only can send one form to become text body, I've code the models like this:
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;
}
}
How can I use multiple parameters to
->setTextBody($this->body)
like
->setTextBody($this->body,$this->gender)
because in view I have several text input
and radio list
to send as an email, how can I do that?
My expectation on the text message will be like:
name
gender
variable 1
variable 2
variable n
SUMMARY edit = both answer is correct but I use
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;}
Thanks for Ankur Garg and Pratik Karmakar
to separate each form(name, gender, etc)? – unknown.person Sep 27 '17 at 06:19