Php 如何使用laravel和gmail发送电子邮件邀请
我需要从我的应用程序向新用户发送电子邮件邀请。我不知道如何管理控制器?这是我的刀片视图Php 如何使用laravel和gmail发送电子邮件邀请,php,laravel-5,gmail,Php,Laravel 5,Gmail,我需要从我的应用程序向新用户发送电子邮件邀请。我不知道如何管理控制器?这是我的刀片视图 @extends('layouts.app') <!-- Main Content --> @section('content') <div class="container"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <div cl
@extends('layouts.app')
<!-- Main Content -->
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Send E-Mail Invitation</div>
<div class="panel-body">
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
<form class="form-horizontal" role="form" method="POST" action="{{ url('/password/email') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}">
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn fa-envelope"></i> Send Invitation Link
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
@extends('layouts.app'))
@节(“内容”)
发送电子邮件邀请
@if(会话(“状态”))
{{session('status')}
@恩迪夫
{{csrf_field()}}
电子邮件地址
@如果($errors->has('email'))
{{$errors->first('email')}
@恩迪夫
发送邀请链接
@端部
我只需要输入一个电子邮件地址并发送邀请邮件。我已将gmail配置为我的电子邮件客户端。你能帮我吗?你可以像这样使用Laravel邮件类发送邮件 您的控制器应如下所示:
use Mail;
class EmailsController {
public function send(Request $request)
{
$email = $request->get('email');
Mail::send('emails.send', ['email' => $email], function ($message) use ($email)
{
$message->from('me@gmail.com', 'Your Name');
$message->to($email);
});
return response()->json(['message' => 'Invitation Email Sent!']);
}
}
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => ['address' => 'me@example.com', 'name' => 'Your name'],
您的视图应该位于目录-resources/views/emails/send.php
<html>
<head></head>
<body style="background: black; color: white">
<h1>Email Invitation</h1>
<p>Hello - {{$email}}</p>
<p>....</p>
</body>
</html>
在对.env
文件进行更改后,不要忘记运行php-artisan-config:cache
。希望这有帮助
还要记得像这样配置您的mail.php
文件iosideconfig/mail.php
:
use Mail;
class EmailsController {
public function send(Request $request)
{
$email = $request->get('email');
Mail::send('emails.send', ['email' => $email], function ($message) use ($email)
{
$message->from('me@gmail.com', 'Your Name');
$message->to($email);
});
return response()->json(['message' => 'Invitation Email Sent!']);
}
}
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => ['address' => 'me@example.com', 'name' => 'Your name'],
如果您需要更多帮助,请在上面配置此文件-allready我已经用gmail配置了My.env。那么我应该重新配置吗?好的,谢谢,我需要一些关于发送此电子邮件的路线的想法。这应该是resources/views/email/send.blade.phpNop该路径将是您在表单操作中提到的路径…--。路由::post('send/activation/mail','EmailsController@send');我可以使用任何控制器发送此电子邮件吗?好的,我当时使用EmailsController编写了此脚本,出现此错误,EmailsController.php第15行中的FatalErrorException:找不到类“App\Http\Controllers\Mail”