我尝试使用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:&#34; phpinfo,system,exec,passthru,proc_open,shell_exec,popen,setlimit,mysql_pconnect,stream_socket_client&#34;
主机禁用这些功能。 (由于安全原因,他们没有赢得他们的支持)。我被告知我可以使用mail()。这究竟是如何工作的?! (smtp,用户名,密码等..)
答案 0 :(得分:0)
这就是我设法让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() }}"/>
应用程序/ HTTP /请求/ 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',
];
}
}
应用程序/ 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