当前位置: 首页 > 知识库问答 >
问题:

Laravel不发送电子邮件也不提供错误

琴镜
2023-03-14

在过去的四个月里,我一直在做一个项目,我对拉拉维尔现在面临的情况非常生气。它不是发送电子邮件;我设置它使用邮件驱动程序并输入正确的代码,但它似乎根本不起作用。除了不工作,它甚至没有给我一个错误!

以下是我的配置:

return array(

/*
|--------------------------------------------------------------------------
| Mail Driver
|--------------------------------------------------------------------------
|
| Laravel supports both SMTP and PHP's "mail" function as drivers for the
| sending of e-mail. You may specify which one you're using throughout
| your application here. By default, Laravel is setup for SMTP mail.
|
| Supported: "smtp", "mail", "sendmail"
|
*/

'driver' => 'mail',

/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| Here you may provide the host address of the SMTP server used by your
| applications. A default option is provided that is compatible with
| the Postmark mail service, which will provide reliable delivery.
|
*/

'host' => 'smtp.mailgun.org',

/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to delivery e-mails to
| users of your application. Like the host we have set this value to
| stay compatible with the Postmark e-mail application by default.
|
*/

'port' => 587,

/*
|--------------------------------------------------------------------------
| 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' => array('address' => null, 'name' => null),

/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/

'encryption' => 'tls',

/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/

'username' => null,

/*
|--------------------------------------------------------------------------
| SMTP Server Password
|--------------------------------------------------------------------------
|
| Here you may set the password required by your SMTP server to send out
| messages from your application. This will be given to the server on
| connection so that the application will be able to send messages.
|
*/

'password' => null,

/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails, we will need to know
| the path to where Sendmail lives on this server. A default path has
| been provided here, which will work well on most of your systems.
|
*/

'sendmail' => '/usr/sbin/sendmail -bs',

/*
|--------------------------------------------------------------------------
| Mail "Pretend"
|--------------------------------------------------------------------------
|
| When this option is enabled, e-mail will not actually be sent over the
| web and will instead be written to your application's logs files so
| you may inspect the message. This is great for local development.
|
*/

'pretend' => false,

);

以下是我发送电子邮件的PHP代码:

$data["mail_message"] = "Hello!";

    Mail::send('emails.welcome', $data, function($message)
    {
        $message
            ->to('me@mydomain.com')
            ->from('info@otherdomain.com')
            ->subject('TEST');
    });

共有3个答案

国景铄
2023-03-14

您可以通过键入以下内容来检查常规电子邮件传递:

php artisan tinker

Mail::getSwiftMailer()->registerPlugin (
    new Swift_Plugins_LoggerPlugin(new Swift_Plugins_Loggers_EchoLogger(false))
);
$to = 'youraddress@example.com';
Mail::raw('Testmail', function ($message) use($to) {  
    $message->to($to)->subject('Testmail'); 
});

你甚至会得到SMTP对话框的输出。

确保用您的邮件地址替换$to,以检查邮件是否到达。

编辑如果这样做有效,并且您在发送电子邮件时仍有问题,则可能会出现排队问题。

司空温书
2023-03-14

在我的场景中,电子邮件正在排队,所以我没有得到任何输出。我忘了在默认情况下将电子邮件设置为队列。我查了一下工作表,看到我所有的留言都在那里等着。我运行了php artisan queue:work来运行/发送队列。

祁景山
2023-03-14

首先,转到app/config/mail。php并将驱动程序更改为“邮件”。同时将主机设置为空。

 类似资料:
  • 我正在使用Laravel,我想使用PHP邮件功能。我已经尝试过了: 但没有电子邮件获取发送至少我不接收它检查垃圾邮件文件夹,它不在那里,我不接收任何错误消息时,执行此代码。 php邮件函数用来发送邮件的是什么?也许我错过了什么? 此外,我没有运行这个地方,我有它上传到我的VPS运行Ubuntu 16.04。1 LTS

  • 我们研发的App可以在用户确认访问我们的分支机构后向其发送电子邮件。当我们使用以下Gmail配置时,它可以正常工作:电子邮件:ainetwgdocs@gmail.comPasswd:XXXXX SMTP服务器:smtp.gmail.com端口:587但是,当我们尝试使用基于域的帐户时,它根本不起作用。我们使用以下参数:电子邮件:contact@ainetw.comPasswd:XXXXX SMTP

  • 当我注册一个用户,或单击“单击此处请求另一个”时,不会发送验证邮件,尽管它的回答是“一个新的验证链接已发送到您的电子邮件地址”。我检查了我的和文件,并使用tinker和

  • 问题内容: 现在,我已经建立了一个PHP电子邮件表单,并且一切正常。但是,在测试时,我只得到了发件人的电子邮件地址作为名称。我想要的是发件人的姓名,例如: 约翰·杜 科目科目科目 代替: j.doe@website.com 科目科目科目 下面是代码… 有谁可以帮助我吗?谢谢。 PHP: 问题答案: 在您的4行说完之后添加一行:

  • 发送电子邮件时,页脚中有下面的标准消息。 此电子邮件是使用CakePHP框架发送的,http://cakephp.org. 它似乎使用了这个: 我的控制器里有这个。 创建了以下视图: /应用程序/查看/电子邮件/文本/梦想。ctp /应用程序/视图/布局/电子邮件/文本/梦想。ctp 是否有任何其他设置我错过了cakephp使用我的布局? *注:如果我重新命名我的梦想。ctp默认。ctp它使用那个

  • 问题内容: 我正在使用sendgrid发送电子邮件,并且使用以下代码可以正常工作,但没有附件。 但是我需要发送附件,因此我搜索了github源和Web文档API,由于某种原因,没有javadocs,但是有一个示例GitHub sendgrid, 所以我一直在尝试直到它起作用为止,我缩小了一些异常和响应代码,起初我是被禁止的未经授权,最好是响应202,表示有效且已排队(在此处检查),这是我的代码发送