【问题标题】:trying to send email with laravel, get an error. What does this mean?尝试使用 laravel 发送电子邮件,收到错误消息。这是什么意思?
【发布时间】:2015-12-08 12:38:08
【问题描述】:

我正在尝试使用 laravel 发送电子邮件,收到错误消息。这是什么意思?

stream_set_blocking() expects parameter 1 to be resource, null given

编辑:邮件代码。

控制器:

public function postSubmit(Request $request)
    {
        Mail::send('emails.contact', ['data' => $request->all()], function ($m) {
            $m->from(config('mail.from.address'), config('mail.from.name'));

            $m->to('xxxxx', 'xxxx')->subject('Contact Form Submitted');
        });
    }

路线:

Route::get('/contact', 'ContactController@index');
Route::post('/contact/submit', 'ContactController@postSubmit');

查看:

 <form role="form" id="feedbackForm" data-toggle="validator" data-disable="false" method="POST" action="{{ url('contact/submit') }}">
 <input type="hidden" name="_token" value="{{ csrf_token() }}" />

发送视图:

<strong>You have a new feedback from contact page!</strong>
<p><strong>Name: </strong> {{$data['name']}}</p>
<p><strong>Email: </strong> {{$data['email']}}</p>
<p><strong>Message: </strong> {{$data['message']}}</p>

Edit2: disable_functions: "phpinfo, system, exec, passthru, proc_open, shell_exec, popen, setlimit, mysql_pconnect, stream_socket_client"

这些功能被主机禁用。 (出于安全原因,他们不会启用它们)。我被告知我可以使用mail()。这究竟是如何工作的?! (smtp、用户名、密码等)

【问题讨论】:

  • 能否请您发布完整的邮件发送代码?
  • 我编辑了正文
  • 我也有同样的问题。你解决了吗?请提供解决方案。
  • @AjmalRazeel 我做到了。请参阅下面的答案。

标签: email laravel


【解决方案1】:

这就是我设法让 laravel 发送电子邮件的方法。

是的,当然。这是我用来为 laravel 配置电子邮件的解决方案。

indexmail.php,根文件夹

 <?php
 if(isset($_POST['submit']))
 {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $query = $_POST['message'];
    $email_from = $name.'<'.$email.'>';

 $to="your-email@your-domain.com";
 $subject="Enquiry!";
 $headers  = 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 $headers .= "From: ".$email_from."\r\n";
 $message="   

         Name:
         $name     
         <br>
         Email-Id:
         $email        
         <br>
         Message:
         $query        

   ";
    if(mail($to,$subject,$message,$headers))
        header("Location:../contact.php?msg=Successful Submission! Thankyou for contacting us.");
    else
        header("Location:../contact.php?msg=Error To send Email !");
        //contact:-your-email@your-domain.com
 }
?>

routes.php

Route::post('/contact/submit', 'ContactController@postSubmit');

配置/mail.php

'from' => ['address' => 'Sender@email.com', 'name' => 'MyName'],




'pretend' => false,

电子邮件视图。

<strong>You have a new feedback from contact page!</strong>
<p><strong>Name: </strong> {{$data['name']}}</p>
<p><strong>Email: </strong> {{$data['email']}}</p>
<p><strong>Message: </strong> {{$data['message']}}</p>

联系表格。

 <form role="form" id="feedbackForm" data-toggle="validator" data-disable="false" method="POST"
                                 action="{{ url('contact/submit') }}">
                               <input type="hidden" name="_token" value="{{ csrf_token() }}"/>

app/Http/Requests/ContactFormRequest.php

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class ContactFormRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required',
            'email' => 'required|email',
            'message' => 'required',
        ];
    }
}

app/User.php

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

让我知道它是否有效! original refference

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-17
    • 2013-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多