2017-11-02 4 views
1

yii2アドバンスコンタクトフォームを使用しています。しかし...コンタクトフォームの電子メールフィールドに充填されたユーザの電子メールを取得できませんアドミニストレーターが取得したメールにメールフォームの連絡フォーム(yii2)

public function sendEmail($email) 
     {  
      return Yii::$app->mailer->compose() 
       ->setTo($email) 
       ->setFrom([$this->email => $this->name]) 
//echo "emailll<pre>";print_r($this->email);exit; 
//here I am getting the correct email which is filled in contact form 
//but when I received mail. nowhere I got That email id... 
// In from: [email protected] which i set as username 
// In To : [email protected] which i set as admin email id   
       ->setSubject($this->subject) 
       ->setTextBody($this->body) 
       ->send(); 
     } 

どのように電子メールを取得しますか?ここ

は、メーラーを使用するには/ contact.php

<?php $form = ActiveForm::begin(['id' => 'contact-form']); ?> 

      <?= $form->field($model, 'name')->textInput(['autofocus' => true]) ?> 

      <?= $form->field($model, 'email') ?> **<--I want this email id to be printed on received mail-->** 

      <?= $form->field($model, 'subject') ?> 

      <?= $form->field($model, 'body')->textarea(['rows' => 2])//->label('Message') ?> 

      <?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [ 
       'template' => '<div class="row"><div class="col-lg-5">{image}</div><div class="col-lg-5">{input}</div></div>', 
      ]) ?> 

      <div class="form-group"> 
       <?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?> 
      </div> 

     <?php ActiveForm::end(); ?> 
+0

あなたの問題は何か明確ではありません。 $ emailアジャストメントを入手できない場合は、contactフォームのビューコードとsendEmailメソッドを実行するメソッドをここに掲載する必要があります。 –

+0

私はアドインのビューコードで質問を更新しました.. –

答えて

1

私はあなたがそのように取得するかもしれないと思う:

public function sendEmail($email) 
    {  
     return Yii::$app->mailer->compose() 
      ->setTo($email) 
      ->setFrom([$this->email => $this->name])   
      ->setSubject($this->subject) 
      ->setTextBody($this->body . ' Email from: ' . $this->email) 
      ->send(); 
    } 
+0

その作業はできますが、setFromで取得できますか? –

+0

いいえ、メールのテキスト内でプロパティを取得する場合は、このようにはできません。 –

+0

しかし、もし私がsetfromでそれを得たら意味をなさないでしょう。 –

0

を見るには、次のようなアプリケーションの設定で、それを構成する必要があります。

[ 
'components' => [ 
    'mailer' => [ 
     'class' => 'yii\swiftmailer\Mailer', 
     'transport' => [ 
      'class' => 'Swift_SmtpTransport', 
      'host' => 'localhost', 
      'username' => 'username', 
      'password' => 'password', 
      'port' => '587', 
      'encryption' => 'tls', 
     ], 
    ], 
    // ... 
], 
], 
+0

提案していただきありがとうございますが、私の設定ファイルにこのコードがありますが、まだメールIDを取得していません。 –

関連する問題