2016-11-24 42 views
0

有人可以告诉我如何发送表单到FormRequest的请求,并从那里发送每个邮件的数据?Laravel FormRequest&Mailables?

这里是我的形式:

<form class="contact__form" style="background-color: #303233 !important;" method="post" action="{{ route('sendContactMail') }}"> 
          <input type="hidden" name="_token" value="{{ csrf_token() }}"> 
          <div class="form-group form-group--light form-group--float"> 
           <input type="text" name="name" class="form-control"> 
           <label>Name</label> 
           <i class="form-group__bar"></i> 
          </div> 
          <div class="form-group form-group--light form-group--float"> 
           <input type="text" name="number" class="form-control"> 
           <label>Email Address</label> 
           <i class="form-group__bar"></i> 
          </div> 
          <div class="form-group form-group--light form-group--float"> 
           <input type="text" name="email" class="form-control"> 
           <label>Contact Number</label> 
           <i class="form-group__bar"></i> 
          </div> 
          <div class="form-group form-group--light form-group--float"> 
           <textarea name="message" class="form-control textarea-autoheight"></textarea> 
           <label>Message</label> 
           <i class="form-group__bar"></i> 
          </div> 

路线sendContactMail

Route::post('/sendmail', ['uses' => '[email protected]', 'as' => 'sendContactMail']); 

用途:[email protected]

public function sendContactMail(ContactFormRequest $request) 
    { 
     \Mail::to('[email protected]')->send(new ContactForm($request)); 
    } 

呀好,我更好地停在这里,因为我跟着一些教程和混合起来,我没有找到FormRequests教程Mailables。

任何人都有提示?

回答

0
public function signUp(Request $request){ 

    $data = $request->all(); 
    $validator = \Validator::make($data, [ 
     'email' => 'email|unique:users' 
     ]); 

    if ($validator->fails()) { 
     return "Invalid Email ID provided or Email might be an existing user. Please enter a valid email address"; 
    }else{ 

     \Mail::send("email.welcome", 
      $dataEmail = array(
      "subjectMsg" => "Welcome to .......", 
      "pass" => $password, 
      "email" => $data['email'] 
      ), function($message) use ($dataEmail) 
      { 
      $message->from("[email protected]", "You Name here"); 
      $message->to($dataEmail['email'])->subject($dataEmail['subjectMsg']); 
      }); 


     if(count(\Mail::failures()) > 0){ 
      return "An error occured. Please try again"; 
     }else { 
      return "success"; 
     }  
     } 



    } 

ROUTE

Route::post('/add-user', '[email protected]'); 

BLABE (resources/views/email/welcome.blade.php) //If you are sending template email

<html> 
<head> 
    <title></title> 
</head> 
<body> 
<h2>Thank you for signing up</h2> 
See your data here: <br> 

Subject in the template: {{ $subjectMsg }} 

Your password:   {{ $pass }} 
Your email:    {{ $email }} 

</body> 
</html> 

记住你的表单操作会提交这条路线:/add-user

+0

您没有使用可邮寄?这个代码看起来很漂亮... messy – Scarwolf

+0

示例代码好友:)它的意思是你的想法。我基本上使用mailgun。所以这里有很多电子邮件服务。代码是发送电子邮件与Laravel。 – Michel

相关问题