laravel 邮件发送_在Laravel中发送电子邮件的最终指南

laravel 邮件发送

Sending emails in web applications has become so essential. Marketing, notifications, newsletters, adverts, etc are some of the reasons why we send emails to our clients. I'd say the majority of websites send automated emails at least via a "Contact us" form.

在Web应用程序中发送电子邮件变得非常重要。 市场营销,通知,新闻通讯,广告等是我们向客户发送电子邮件的一些原因。 我想大多数网站至少会通过“与我们联系”表格发送自动电子邮件。

Let's explore the many possible ways to send emails in a Laravel application.

让我们探索在Laravel应用程序中发送电子邮件的多种可能方式。

选择电子邮件服务提供商 ( Choosing An Email Service Provider )

Although your first thought when you see "Email Service Provider" may be service providers in Laravel, that is not what I am referring to here. I am referring to online services that provide email sending functionalities via APIs.

尽管当您看到“电子邮件服务提供商”时最初想到的可能是Laravel中的服务提供商,但这不是我在这里指的。 我指的是通过API提供电子邮件发送功能的在线服务。

You might be wondering why you need to make use of a service when you can just go hardcore with SMTP. The old way works fine, no doubt, but if you really want something awesome, robust, scalable and economic, then a service provider is better as it does all the hard jobs and just gives you an endpoint for your program to talk to,

您可能想知道为什么仅通过SMTP进行硬核时为什么需要使用服务。 毫无疑问,旧方法可以很好地工作,但是如果您真的想要一些很棒,强大,可扩展且经济的东西 ,那么服务提供商会更好,因为它可以完成所有艰苦的工作,并为您提供程序可以与之对话的端点,

We are going to review several possible providers and how to set them up in a Laravel application. Speaking of which, install a new Laravel application and leave config/services.php open in your favorite editor.

我们将审查几种可能的提供程序,以及如何在Laravel应用程序中进行设置。 说到这, 安装一个新的Laravel应用程序,并在您喜欢的编辑器中将config/services.php打开状态。

Mailgun (Mailgun)

  1. Sign up for an account if you have not.

    如果尚未注册,请注册一个帐户。

  2. Verify your email and phone number.

    验证您的电子邮件和电话号码。

  3. You will be redirected to your Dashboard.

    您将被重定向到仪表板。

  4. Locate your API Key and domain

    找到您的API密钥和域

邮件陷阱 (Mailtrap)

Mailtrap is awesome for development and testing. It was not built with sending emails in production in mind.

Mailtrap非常适合开发和测试。 它并不是在生产时就发送电子邮件的。

  1. Registier via https://mailtrap.io/register/signup

    通过https://mailtrap.io/register/signup注册
  2. Verify if necessary

    必要时验证
  3. Access your inboxes via https://mailtrap.io/inboxes

    通过https://mailtrap.io/inboxes访问您的收件箱
  4. Store the SMTP credentials somewhere safe

    将SMTP凭据存储在安全的地方

山d (Mandrill)

  1. Sign up

    注册

  2. Setup a domain name

    设置域名

  3. Go to settings from the left menu

    从左侧菜单转到设置

  4. Click Add API key

    点击添加API密钥

  5. Add Mandrill option in the config/services.php file

    config/services.php文件中添加Mandrill选项

'mandrill' => [
        'secret' => env('MANDRILL_KEY'),
    ],

There are several more options, including Amazon SES, but we will just focus on a few. They are all very similar to setup so let us just stick with learning with what we have.

还有更多选项,包括Amazon SES,但我们仅关注其中几个。 它们都与设置非常相似,因此让我们坚持学习已有的东西。

配置我们的服务 ( Configuring Our Services )

Our config/services.php has all the configuration for major external services that are required for our application. It is also recommended that if Laravel does not provide any service, you should stick to the design pattern of using the services config file to configure your application.

我们的config/services.php具有应用程序所需的主要外部服务的所有配置。 还建议如果Laravel不提供任何服务,则应坚持使用services config文件配置应用程序的设计模式。

'mailgun' => [
        'domain' => env('MAILGUN_DOMAIN'),
        'secret' => env('MAILGUN_SECRET'),
    ],

    'mandrill' => [
        'secret' => env('MANDRILL_KEY'),
    ],

    'ses' 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值