gpt4 book ai didi

php - Laravel 发送邮件 SMTP

转载 作者:行者123 更新时间:2023-12-04 02:09:40 26 4
gpt4 key购买 nike

谁能帮我 Laravel 邮件功能 ?

我改了 config/mail.php 归档到

'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'mail.concept.kz'),
'port' => env('MAIL_PORT', 25),
'from' => ['address' => 'support@concept.kz', 'name' => 'asdf'],
'encryption' => env('MAIL_ENCRYPTION', null),
'username' => env('support@concept.kz'),
'password' => env('mypassword'),
'sendmail' => '/usr/sbin/sendmail -bs',

这是我在 Controller 中的代码
Mail::raw($messageBody, function($message) {
$message->from('support@concept.kz', 'Learning Laravel');
$message->to('receiver@mail.ru');
});

if (Mail::failures()) {
echo 'FAILED';
}
return redirect()->back();

我对 做了同样的更改.env 文件,但没有任何 react 。
谁能给我建议该怎么做?难道我做错了什么?

最佳答案

从您的网站发送电子邮件

  • 创建用户发送电子邮件的 View :
    {!! Form::Open(['url' => 'sendmail']) !!}

    <div class="col_half">
    {!! Form::label('name', 'Name: ' ) !!}
    {!! Form::text('name', null, ['class' => 'form-control', 'required']) !!}
    </div>

    <div class="col_half col_last">
    {!! Form::label('email', 'E-Mail: ' ) !!}
    {!! Form::email('email', null, ['class' => 'form-control', 'required']) !!}
    </div>

    <div class="clear"></div>

    <div class="col_full col_last">
    {!! Form::label('subject', 'Subject: ' ) !!}
    {!! Form::text('subject', null, ['class' => 'form-control', 'required']) !!}
    </div>

    <div class="clear"></div>

    <div class="col_full">
    {!! Form::label('bodymessage', 'Message: ' ) !!}
    {!! Form::textarea('bodymessage', null, ['class' => 'form-control', 'required', 'size' => '30x6']) !!}
    </div>


    <div class="col_full">
    {!! Form::submit('Send') !!}
    </div>
    {!! Form::close() !!}

  • 1a.在 Controller 中创建此函数:
    public function sendMail(Request $request) {
    //dd($request->all());

    $validator = \Validator::make($request->all(), [
    'name' => 'required|max:255',
    'email' => 'required|email|max:255',
    'subject' => 'required',
    'bodymessage' => 'required']
    );

    if ($validator->fails()) {
    return redirect('contact')->withInput()->withErrors($validator);
    }


    $name = $request->name;
    $email = $request->email;
    $title = $request->subject;
    $content = $request->bodymessage;


    \Mail::send('emails.visitor_email', ['name' => $name, 'email' => $email, 'title' => $title, 'content' => $content], function ($message) {

    $message->to('your.email@gmail.com')->subject('Subject of the message!');
    });


    return redirect('contact')->with('status', 'You have successfully sent an email to the admin!');

    }
  • 在路由文件
  • 中创建到该函数的路由
  • 在/resources/views/emails/visitor_email.blade.php 中创建一个 Blade.php View 文件
    有了这个内容:
      <p>Name: {{ $name }}</p>
    <p>E-Mail: {{ $email }}</p>
    <p>Subject: {{ $title }}</p>
    <p>Message: <br>
    {{ $content }}</p>
  • 在 .env 文件中,将您的数据用于发送这样的电子邮件
    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=587
    MAIL_USERNAME=your.email@gmail.com
    MAIL_PASSWORD=email-password
    MAIL_ENCRYPTION=tls

  • 这应该有效!如果您需要更多帮助,请询问!

    关于php - Laravel 发送邮件 SMTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39838646/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com