A
A
Alexander Ivanov2017-09-09 10:38:00
Yii
Alexander Ivanov, 2017-09-09 10:38:00

Why do two emails come from one yii2 form?

Two letters began to arrive instead of one
yiiframework.ru/forum/viewtopic.php?t=21446 - I tried it, but nothing seems to change
Implemented through widgets
One model is responsible for all sending

public function contact($email)
  {
    if($this->...){
      $message = "Имя: {$this->name}\nEmail или телефон: {$this->phone}\nСообщение: {$this->body}\n\nСообщение с сайта: {$this->url_site}";
      if ($this->validate()) {
        Yii::$app->mailer->compose()
          ->setTo([
//            ..
          ])
          ->setFrom([$this->email => $this->name])
          ->setSubject($this->subject."ъзъх")
          ->setTextBody($message)
          ->send();

        return true;
      }
    }
    return false;
  }

Widget code example
<?php

namespace app\components;

use Yii;
use yii\base\Widget;
use app\models\ContactForm;

class FBFWidget extends Widget
{
    public function run()
    {
        $model = new ContactForm();
        if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
        Yii::$app->session->setFlash('contactFormSubmitted');
        }
        return $this->render('fbfWidget', [
            'model' => $model,
        ]);
    }
}

I tried to turn off the widgets in turn, I still received two letters each.
What you should pay attention to?
____
It is also surprising that this feature began on the day when I didn’t seem to sit down for it, and I haven’t touched the forms for a long time. Generally strange behavior.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2017-09-15
@cimonlebedev

A similar problem can occur in the Google Chrome browser if the favicon.ico file is missing in the root of the site.
About this problem on Habré
It is treated either by adding a favicon.ico file or by setting htaccess

K
Kaviol Sevastopol, 2020-10-12
@trudofan

I have the same story stuck on the background of inactivity.
Button in JS:

$('#formvopros').submit(function(s){
  
if($('#bloxa').val()){
       $('.text_voprosa').css({'background-color':'rgba(171, 220, 255,.7)'});
   s.preventDefault();
    var b = $(this);
    $.ajax({
            type: "POST",
            url: "obr_vopros.php",
            data: b.serialize(),
            success:  function() {
                vi_4.fadeOut();
                vi_5.animate({'top':'50%'},1000);
                setTimeout(funpris,5000);
            }
    }); 
} else{
   $('.iitog p').html('Укажите действительные данные');
   $('.text_voprosa').css({'background-color':'rgba(250, 2, 2,.5)'});
   s.preventDefault();
}
});

In HTML:
<p class="vopros on_5"><input type="submit" class="bot in_5" valur="Отправить"></p>

And the handler:
mail("[email protected]","Заказан просчет стоимости ремонта","Содержание сообщения:".$telo,"From: [email protected] \r\n");

It would seem where dubbing can come from. But! There was a problem that nothing was sent at all. Wrote in support for hosting. They poked around and began to arrive in two letters. I wrote to them again about the problem. I think they will. 100% their bad.
I am a developer of simple and high-conversion sites from RA KAVIOL , so the main thing is marketing in the subject, and programming is only superficial - the development of gaming components

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question