Laravel/XAMPP/Sendmail 不发送邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16874528/
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 07:51:30  来源:igfitidea点击:

Laravel/XAMPP/Sendmail not sending mail

apachelaravelsmtpxamppsendmail.exe

提问by Sterling Duchess

I have the same problem with XAMPP and WAMP. I'm unsure what causes this problem as there is absolutely nothing in log files.

我对 XAMPP 和 WAMP 有同样的问题。我不确定是什么导致了这个问题,因为日志文件中绝对没有。

I triple checked my configuration and everything is as it should be I even turned off my firewall and yet nothing happens.

我三重检查了我的配置,一切都应该如此我什至关闭了我的防火墙,但没有任何反应。

Laravel 4 throw's this (timeout) exception: Symfony\Component\Debug\Exception\FatalErrorException

Laravel 4 抛出这个(超时)异常: Symfony\Component\Debug\Exception\FatalErrorException

\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php165

public function readLine($sequence)
{
    if (isset($this->_out) && !feof($this->_out)) {
        $line = fgets($this->_out);
        if (strlen($line)==0) {

This function Laravel 4 uses to read the template file. However no problem accessing the file either as it is properly named and in proper folder. The method that send's the mail is this one:

Laravel 4 使用这个函数来读取模板文件。但是,访问该文件没有问题,因为它的名称正确且位于正确的文件夹中。发送邮件的方法是这样的:

    Mail::send('emails.activate', array('url' => $url), function($message) {
        $message->to(trim(Input::get('email')))->subject('Account activation.');
    });

And Laravel's mail.php from config folder:

和 Laravel 的 mail.php 来自 config 文件夹:

<?php

return array(
    'driver' => 'smtp', // Changed this to mail() and sendmail same error
    'host' => 'smtp.gmail.com',
    'port' => 465,
    'from' => array('address' => '[email protected]', 'name' => 'Support Team'),
    'encryption' => 'tls',
    'username' => '****@gmail.com',
    'password' => '*****',
    'sendmail' => 'C:\xampp\sendmail\sendmail.exe -t',
);

In my php.ini file I have:

在我的 php.ini 文件中,我有:

[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = smtp.gmail.com
smtp_port = 465

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = ****@gmail.com


; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

And in my sendmail.ini I have:

在我的 sendmail.ini 中,我有:

smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
auth_username=****@gmail.com
auth_password=****
pop3_server=
pop3_username=
pop3_password=
force_sender=
force_recipient=
hostname=

I have everything set properly, i turned off firewall, checked my router cant trace it anyhow.

我已经正确设置了一切,我关闭了防火墙,检查了我的路由器无论如何都无法跟踪它。

回答by LifeQuery

I posted an answer herethat may solve this for some.

我在这里发布了一个答案,可能会为某些人解决这个问题。

In short, when using port 465, the default encryption setting needs to be changed from tls to ssl.

总之,在使用465端口时,需要将默认的加密设置从tls改为ssl。

'host' => 'smtp.gmail.com',
'port' => 465, 
'encryption' => 'ssl',

回答by kJamesy

You probably figured it out by now, but I think the problem is with your

你现在可能已经想通了,但我认为问题出在你的

    Mail::send('emails.activate', array('url' => $url), function($message) {
    $message->to(trim(Input::get('email')))->subject('Account activation.');
});

Try changing it to:

尝试将其更改为:

    $to = trim(Input::get('email'));
    $subject = 'Account activation.'; //for illustration purposes
    Mail::send('emails.activate', array('url' => $url), function($message) use ($to, $subject){
    $message->to($to)->subject($subject);
});

回答by vstruhar

If gmail is blocking you and won't let you signin with your credentials try this.

如果 Gmail 阻止您并且不允许您使用您的凭据登录,请尝试此操作。

Login with your gmail account and than go to: https://accounts.google.com/b/0/DisplayUnlockCaptcha

使用您的 Gmail 帐户登录,然后转到:https: //accounts.google.com/b/0/DisplayUnlockCaptcha

and click continue and than you have few minutes to send your mail with your code. After this google will allow signin to that account from the new source.

然后单击继续,然后您有几分钟的时间发送带有代码的邮件。在此之后,谷歌将允许从新来源登录该帐户。