我正在尝试使用 sendmail 驱动程序发送电子邮件,但它不起作用并且没有出现任何错误。
我的.env
文件:
MAIL_DRIVER=sendmail
MAIL_HOST=
MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
我的mail.php
文件:
<?php
return [
/*
|--------------------------------------------------------------------------
| 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", "sendmail", "mailgun", "mandrill", "ses",
| "sparkpost", "log", "array"
|
*/
'driver' => env('MAIL_DRIVER', 'sendmail'),
/*
|--------------------------------------------------------------------------
| 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 Mailgun mail service which will provide reliable deliveries.
|
*/
'host' => env('MAIL_HOST', ''),
/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/
'port' => env('MAIL_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' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'INSP Virtual'),
],
/*
|--------------------------------------------------------------------------
| 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' => env('MAIL_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' => env('MAIL_USERNAME', null),
'password' => env('MAIL_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',
/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
|--------------------------------------------------------------------------
|
| If you are using Markdown based email rendering, you may configure your
| theme and component paths here, allowing you to customize the design
| of the emails. Or, you may simply stick with the Laravel defaults!
|
*/
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
由于我没有收到任何错误,即使在 laravel.log 文件中我都不知道从哪里开始检查,但我已经检查了正确的 sendmail 路径,并且它是正确的,我遗漏了什么?
我还读到你必须在 /etc/hosts 中更改一些内容我对其进行了一些更改,添加了“inspvirtual.mx”,但我不太确定这是否正确:
127.0.0.1 inspvirtual.mx
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
在我尝试发送电子邮件后,邮件日志打印出以下内容:
May 26 14:12:35 inspvirtual sendmail[3130]: x4Q9BDjB010067: to=<[email protected]>, delay=09:01:22, xdelay=00:00:00, mailer=esmtp, pri=1020554, relay=mail.juicyboom.com., dsn=4.0.0, stat=Deferred: Connection timed out with mail.juicyboom.com.
May 26 14:12:35 inspvirtual sendmail[3130]: x4Q9BWIJ010111: to=<[email protected]>, delay=09:01:03, xdelay=00:00:00, mailer=esmtp, pri=1020554, relay=mail.juicyboom.com., dsn=4.0.0, stat=Deferred: Connection timed out with mail.juicyboom.com.
May 26 14:12:35 inspvirtual sendmail[3130]: x4Q9CdaV010235: to=<[email protected]>, delay=08:59:56, xdelay=00:00:00, mailer=esmtp, pri=1020554, relay=mail.juicyboom.com., dsn=4.0.0, stat=Deferred: Connection timed out with mail.juicyboom.com.
May 26 14:12:35 inspvirtual sendmail[3130]: x4Q9Nnob011458: to=<[email protected]>, delay=08:48:46, xdelay=00:00:00, mailer=esmtp, pri=1020554, relay=mail.juicyboom.com., dsn=4.0.0, stat=Deferred: Connection timed out with mail.juicyboom.com.
May 26 14:12:35 inspvirtual sendmail[3130]: x4Q8pH0A007887: to=<[email protected]>, delay=09:21:18, xdelay=00:00:00, mailer=esmtp, pri=1020560, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
May 26 14:12:35 inspvirtual sendmail[3130]: x4Q8rkK3008160: to=<[email protected]>, delay=09:18:49, xdelay=00:00:00, mailer=esmtp, pri=1020560, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
May 26 14:12:35 inspvirtual sendmail[3130]: x4Q8TUXJ005341: to=<[email protected]>, delay=09:43:05, xdelay=00:00:00, mailer=esmtp, pri=1110560, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
May 26 14:12:35 inspvirtual sendmail[3130]: x4Q8Wnpn005708: to=<[email protected]>, delay=09:39:46, xdelay=00:00:00, mailer=esmtp, pri=1110560, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
May 26 14:12:35 inspvirtual sendmail[3130]: x4Q8bZaD006249: to=<[email protected]>, delay=09:35:00, xdelay=00:00:00, mailer=esmtp, pri=1110560, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
May 26 14:12:35 inspvirtual sendmail[3130]: x4Q8fPQg006712: to=<[email protected]>, delay=09:31:10, xdelay=00:00:00, mailer=esmtp, pri=1110560, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
重要的是要说,由于这是一个专用服务器,我手动配置了该服务器上所有必要的内容才能正常工作,例如 DNS。
我还更改了/etc/mail/sendmail.mc
文件,在这一行:
LOCAL_DOMAIN(`inspvirtual.mx')dnl
我还运行hostname
检查主机名是否正确,并打印出正确的主机名:inspvirtual.mx
我对从 0 开始手动配置服务器还很陌生,所以我有点迷茫……
答案1
作为迈克尔·汉普顿建议
如果所有发出的消息都保持在队列中connection timed out
然后最有可能的是,你的传出 SMTP 连接被阻止(防火墙阻止),例如被你的 ISP 或你的内部网防火墙阻止
建议的验证程序:
1. 检查是否收到 SMTP 问候消息 [是 sendmail 故障吗?]
telnet mail.juicyboom.com 25
2. 使用类似工具tcptraceroute
来定位防火墙位置