S
S
Svetlana Galenko2018-11-14 22:16:06
Yii
Svetlana Galenko, 2018-11-14 22:16:06

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".
5bec737393d8b966400945.png
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;
    }
}

I understand that you can not use these settings:
->setPhone($this->phone)
->setDate($this->date)
->setName($this->subject)
->setEmail($this->email)

How can this be spelled correctly?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question