2017-08-12 129 views
0

我有网站make在Laravel 5.4。我的联系方式,并尝试发送邮件,但是当我发送了邮件中的这个数据Laravel 5.4 - 发送邮件

Name: {{ $name }} 

Email: {{ $email }} 

Message: {{ $message1 }} 

在laravel 5.1我得到的数据,但在Laravel 5.4,我不能传递数据。

我web.php

Route::post('mailContact', '[email protected]'); 

我contorller:

protected function postEmailContact() { 

    Mail::send('requestContact', array(
     'name' =>Input::get("name"), 
     'email' =>Input::get("email"), 
      'message1' =>Input::get("message1") 

    ), function ($message) { 

    $message->from('[email protected]', 'Contact'); 

    $message->to('[email protected]')->subject('Contact'); 

}); 
    return redirect('/'); 
} 

和我requestContact.blade.php

Name: {{ $name }} 
Email: {{ $email }} 
Message: {{ $message1 }} 

和contact.blade.php

{!! Form::open(array('url' => 'mailContact','class'=>'form-group')) !!} 
        <div id="content-page" class="content group"> 
         <div class="hentry group"> 
          <div class="usermessagea"></div> 
              <label for="name-contact-us"> 
              Name 
              </label> 
              <div class="input-prepend"> {!! Form::text('name', null, array('class' => 'form-control','placeholder' => 'ime')) !!}</div> 
              <div class="msg-error"></div> 

              <label for="email-contact-us"> 
              Email 
              </label> 
              <div class="input-prepend"> {!! Form::text('name', null, array('class' => 'form-control','placeholder' => 'email')) !!}</div> 
              <div class="msg-error"></div> 

              <label for="message-contact-us"> 
              Message 
              </label> 
             <div class="input-prepend">  {!! Form::textarea('message1', null, 
        array('placeholder'=>'message', 
        'class'=>'form-control' 
        )) !!}</div> 

            </br> 
             {!! Form::submit('send' , array('class' => 'btn btn-primary')) !!}     

        </div> 
        {!! Form::close() !!} 

有什么想法?如何传递数据?

+0

请检查你有没有电子邮件领域,但两者字段名作为名称字段 –

+0

我不得不更换名字电子邮件,但同样的,无牌数据 – dev

回答

0

你应该试试这个:

请更改email

{!! Form::text('name', null, array('class' => 'form-control','placeholder' => 'email')) !!} 

TO

{!! Form::text('email', null, array('class' => 'form-control','placeholder' => 'email')) !!} 

更新答案

protected function postEmailContact() { 

$data = array(
     'name' =>Input::get("name"), 
     'email' =>Input::get("email"), 
      'message1' =>Input::get("message1") 

    ); 

    Mail::send('requestContact',$data, function ($message) { 

    $message->from('[email protected]', 'Contact'); 

    $message->to('[email protected]')->subject('Contact'); 

}); 
    return redirect('/'); 
} 

希望为你工作!!!

+0

好吧,让我检查一下 –

+0

@dev请显示结果集中的所有输入数据如$ data = Input :: all(); dd($ data) –

+0

@dev请检查我更新的答案并试试这个 –

0
Follow 3 step only 
1] configure in .evn file at root dir. as above 
    MAIL_DRIVER=smtp 
    MAIL_HOST=smtp.gmail.com 
    MAIL_PORT=587 
    [email protected] 
    MAIL_PASSWORD=****** 
    MAIL_ENCRYPTION=tls 


2]create controller 
    use Mail; 
    class mailController extends Controller 
    { 
    public function send(){ 
     Mail::send(
      ['text' => 'post.mail'], //e.g post/mail.blade.php <view file mentioned here> 
      ['name' => 'Name'], 
      function($message){ 
       $message->to('[email protected]','To username'); 
       $message->subject('test email yagnesh'); 
       $message->from('[email protected]','from username'); 
      } 
     ); 
    } 
} 

AND create view file <post/mail.blade.php> set this name 

3] run command at root dir. to Restart server <php artisan serve> 
    And 
    U can allow google less security at [https://www.google.com/settings/security/lesssecureapps][1] 
    Just enabled 

4] create Route 
    //for send mail 

     Route::get('/send','[email protected]'); 
    and run 'send' keyword in your url. 

For more visit <https://www.youtube.com/watch?v=a08ouL3wjjQ&list=PLe30vg_FG4OQz1yZq0z19ZuWD_C3MZbA4&index=26> 
Good luck!!!