Answer the question
In order to leave comments, you need to log in
How to make sure that letters from the site come to the mail correctly?
Hello, I set up mail, but letters come only with the content "message".
Please help me how to set up letters to come with a phone number, username, date, mail that the user entered on the site. Here is my model:
class AppointmentForm extends ActiveRecord
{
public $name;
public $email;
public $phone;
public $date;
public $body;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'system_appointment';
}
/**
* @return array the validation rules.
*/
public function rules()
{
return [
// name, email, subject and body are required
[['name', 'email', 'phone', 'date', 'body'], 'required'],
// email has to be a valid email address
['email', 'email'],
];
}
/**
* Sends an email to the specified email address using the information collected by this model.
* @param string $email the target email address
* @return bool whether the model passes validation
*/
public function appointment($email)
{
$content = "<p>Email: " . $this->email . "</p>";
$content .= "<p>Name: " . $this->name . "</p>";
$content .= "<p>Phone: " . $this->phone . "</p>";
$content .= "<p>Date: " . $this->date . "</p>";
$content .= "<p>Body: " . $this->body . "</p>";
if ($this->validate()) {
Yii::$app->mailer->compose(["content" => $content])
->setTo('[email protected]')
->setFrom([\Yii::$app->params['supportEmail'] => $this->name])
->setTextBody($this->body)
->send();
return true;
}
return false;
}
}
->setPhone($this->phone)
->setDate($this->date)
->setName($this->subject)
->setEmail($this->email)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question