【问题标题】:call mail function in json response in laravel在laravel的json响应中调用邮件函数
【发布时间】:2016-11-02 12:27:34
【问题描述】:

我想在 laravel 5.3 的 jquery 页面中调用邮件功能。我的邮件路由器名称为 'welcome-mail'

Route::get('welcome-mail','travelerHome@welcomeMail');

Controller 
 public function welcomeMail()
{
    $to_email = 'sample@domain.com';
    Mail::to($to_email)->send(new Reminder);
    //return "E-mail has been sent Successfully";  
}

mail/Remainder.php
public function build()
{
    return $this->from('sample@toDomain.com')
                ->view('email.welcome');
}

view/email/welcome.blade.php
<html>
<body>
  <h3>Hi,</h3> 
   <p>Test mail Travel approval</p>
</body>
</html>

我想在 json 响应或者 json url 中调用这个函数

if(approve_id=='Y'){
    var status = 'approved';
    $.ajax({
  url: 'request-status',
  type: 'GET',
  data: {'id':user_id,'status':status,'comment':comment}, 
  dataType: 'JSON',
  success: function(data, textStatus, jqXHR){
    //alert(data);
    url: 'welcome-mail'   //want to call like this
    $(".table-responsive").load(location.href + " .table-responsive");
  },
  error: function(jqXHR, textStatus, errorThrown){
 // alert('errror');

  },
});
  }

【问题讨论】:

    标签: php jquery json laravel email


    【解决方案1】:

    请在控制器请求状态中处理您的欢迎邮件,而不是 ajax 响应。

    或者

    $.ajax({
      type: "POST",
      url: "/request-status",
      data: {'id':user_id,'status':status,'comment':comment}, 
      success: function (data) { SuccessCall(data); },
      error: function (xhr, status, error) { alert(error); }
             });
    
    
    function SuccessCall(data){
     $.ajax({
     type: "POST",
     url: "welcome-mail",
     success: function (data) { //Success message },
     error: function (xhr, status, error) { alert(error); }
     });
     }
    

    【讨论】:

    • 在我的控制器中我尝试了 //Route::get('welcome-mail','travelerHome@welcomeMail');
    猜你喜欢
    • 2019-08-29
    • 2021-09-15
    • 2018-03-02
    • 2018-01-14
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 2015-01-13
    • 1970-01-01
    相关资源
    最近更新 更多