{ | { | ||||
$message = $this->composeBase($toEmail, $view, $params); | $message = $this->composeBase($toEmail, $view, $params); | ||||
$this->initMessageFromProducer($message, $subject, $producer); | $this->initMessageFromProducer($message, $subject, $producer); | ||||
$message->send(); | |||||
return $message->send(); | |||||
} | } | ||||
public function sendFromSite(string $subject, string $view, array $params, string $toEmail) | public function sendFromSite(string $subject, string $view, array $params, string $toEmail) | ||||
{ | { | ||||
$message = $this->composeBase($toEmail, $view, $params); | $message = $this->composeBase($toEmail, $view, $params); | ||||
$this->initMessageFromSite($message, $subject); | $this->initMessageFromSite($message, $subject); | ||||
$message->send(); | |||||
return $message->send(); | |||||
} | |||||
public function sendProducer(Producer $producer, string $subject, string $view, array $params = [], string $replyTo = null) | |||||
{ | |||||
$message = $this->composeBase($producer->contact_email, $view, $params); | |||||
if($replyTo) { | |||||
$message->setReplyTo($replyTo); | |||||
} | |||||
$this->initMessageFromSite($message, $subject); | |||||
return $message->send(); | |||||
} | } | ||||
public function sendAdmin(string $subject, string $view, array $params = [], string $replyTo = null) | public function sendAdmin(string $subject, string $view, array $params = [], string $replyTo = null) | ||||
$message->setReplyTo($replyTo); | $message->setReplyTo($replyTo); | ||||
} | } | ||||
$this->initMessageFromSite($message, $subject); | $this->initMessageFromSite($message, $subject); | ||||
$message->send(); | |||||
return $message->send(); | |||||
} | } | ||||
private function composeBase(string $toEmail, string $view, array $params = []) | private function composeBase(string $toEmail, string $view, array $params = []) |
namespace common\forms; | namespace common\forms; | ||||
use common\logic\Producer\Producer\Model\Producer; | |||||
use Yii; | use Yii; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
* @param string $email the target email address | * @param string $email the target email address | ||||
* @return boolean whether the email was sent | * @return boolean whether the email was sent | ||||
*/ | */ | ||||
public function sendEmail($email) | |||||
public function sendEmail(Producer $producer) | |||||
{ | { | ||||
return Yii::$app->mailer->compose([ | |||||
'html' => 'contact-html', | |||||
'text' => 'contact-text'], [ 'content' => $this->body, | |||||
return Yii::$app->mailerService->sendProducer( | |||||
$producer, | |||||
'Contact : ' . $this->subject, | |||||
'contact', | |||||
[ | |||||
'content' => $this->body, | |||||
'name' => $this->name | 'name' => $this->name | ||||
]) | |||||
->setTo($email) | |||||
->setFrom([$this->email => $this->name]) | |||||
->setSubject('[Opendistrib] Contact : ' . $this->subject) | |||||
->send(); | |||||
], | |||||
$this->email | |||||
); | |||||
} | } | ||||
} | } |
$model = new ContactForm(); | $model = new ContactForm(); | ||||
$producer = $this->getProducerCurrent(); | $producer = $this->getProducerCurrent(); | ||||
/*if ($model->load(\Yii::$app->request->post()) && $model->validate()) { | |||||
if ($model->load(\Yii::$app->request->post()) && $model->validate()) { | |||||
$isSent = false; | $isSent = false; | ||||
if (is_array($producer->contact)) { | |||||
$email = $this->getProducerModule()->getMainContactEmail($producer); | |||||
if (strlen($email) && $model->sendEmail($email)) { | |||||
$isSent = true; | |||||
} | |||||
if ($producer->contact_email && strlen($producer->contact_email) > 0 && $model->sendEmail($producer)) { | |||||
$isSent = true; | |||||
} | } | ||||
if ($isSent) { | if ($isSent) { | ||||
} | } | ||||
$model = new ContactForm(); | $model = new ContactForm(); | ||||
}*/ | |||||
} | |||||
return $this->render('contact', [ | return $this->render('contact', [ | ||||
'model' => $model, | 'model' => $model, |
?> | ?> | ||||
<div class="site-contact"> | <div class="site-contact"> | ||||
<div class="alert alert-warning">Page en maintenance</div> | |||||
<!--<div class="row"> | |||||
<div class="row"> | |||||
<div class="col-lg-5"> | <div class="col-lg-5"> | ||||
<?php $form = ActiveForm::begin(['id' => 'contact-form', 'enableClientValidation' => false,]); ?> | <?php $form = ActiveForm::begin(['id' => 'contact-form', 'enableClientValidation' => false,]); ?> | ||||
<?= $form->field($model, 'name') ?> | <?= $form->field($model, 'name') ?> | ||||
</div> | </div> | ||||
<?php ActiveForm::end(); ?> | <?php ActiveForm::end(); ?> | ||||
</div> | </div> | ||||
</div>--> | |||||
</div> | |||||
</div> | </div> |