如何使用默认的 Laravel 模板发送电子邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42566556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:27:26  来源:igfitidea点击:

how to send an email with the default laravel template

laravelemail

提问by programmer

How can i send an email on laravel by using the default template ? ?

如何使用默认模板在 laravel 上发送电子邮件??

what i mean in the default html template is the same template that used for resetting password for example ...

我在默认 html 模板中的意思是用于重置密码的相同模板,例如......

anyway please ? ?

无论如何请??

回答by tanay jha

If you are using Laravel 5.3 or 5.4, you should first publish the mail views using:

如果您使用的是 Laravel 5.3 或 5.4,您应该首先使用以下命令发布邮件视图:

php artisan vendor:publish --tag=laravel-mail 

That will copy the blade files to resources/views/vendor/mail. Then the build method of your Mailable class can call the required mail template.

这会将刀片文件复制到资源/视图/供应商/邮件。然后你的 Mailable 类的 build 方法可以调用所需的邮件模板。

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->from('[email protected]')
                ->view('emails.orders.shipped');
}

See the docsfor more details.

有关更多详细信息,请参阅文档

回答by Dom DaFonte

This is how I send emails using the Mail class that ships with Laravel.

这就是我使用 Laravel 附带的 Mail 类发送电子邮件的方式。

$user = PlaceUserObjectHere;
$emailType = 'Comment';
$emailView = 'emails.standardTemplate';
$emailContent = PlaceContent Object here;
$emailContent['Content'] = 'Place Email Body Here';
$emailSubject = 'Place Subject Line Here ';
$emailContent['Header'] = $emailSubject;
$emailContent['buttonURL'] = '/';
$emailContent['buttonTitle'] = 'Button Text';

Mail::send($emailView, ['user' => $user, 'emailContent' => $emailContent], function ($m) use ($user, $emailSubject) {
                $m->from('[email protected]', 'emailName');
                $m->to($user->first()->email, $user->first()->fname . ' ' . $user->first()->lname)->subject($emailSubject);
            });

Here is the standardTemplate.

这是标准模板。

<div class='container' text-align="center">
    <h3 class="panel-title navbar-brand">{!! $emailContent['Header'] !!}</h3>
{!! $emailContent['Content'] !!}
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center">
      <div>
        <a href="{{url($emailContent['buttonURL'])}}" style="background-color:#2a3e68;border:1px solid #2a3e68;border-radius:3px;color:#ffffff;display:inline-block;font-family:sans-serif;font-size:16px;line-height:44px;text-align:center;text-decoration:none;width:300px;-webkit-text-size-adjust:none;mso-hide:all;">{{$emailContent['buttonTitle']}}</a>
      </div>
    </td>
  </tr>
</table>
@include('emails.partial.footer')
        </div>

Hope this helps.

希望这可以帮助。

回答by Ahmed Abdulrahman