Laravel无法发送电子邮件,且没有错误

w6mmgewl  于 2023-06-24  发布在  其他
关注(0)|答案(5)|浏览(144)

我一直在做一个项目1个月,真的很困惑,为什么我没有得到电子邮件,我按照教程,并尝试在其他项目没有任何错误,我得到了电子邮件,但我合并后,我的项目,我没有得到电子邮件
这是我的配置

/*
|--------------------------------------------------------------------------
| 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", "postmark", "log", "array"
|
*/

'driver' => env('MAIL_DRIVER', 'smtp'),

/*
|--------------------------------------------------------------------------
| 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.mailgun.org'),

/*
|--------------------------------------------------------------------------
| 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', 'hello@example.com'),
    'name' => env('MAIL_FROM_NAME', 'Example'),
],

/*
|--------------------------------------------------------------------------
| 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'),

'password' => env('MAIL_PASSWORD'),

/*
|--------------------------------------------------------------------------
| 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'),
    ],
],

/*
|--------------------------------------------------------------------------
| Log Channel
|--------------------------------------------------------------------------
|
| If you are using the "log" driver, you may specify the logging channel
| if you prefer to keep mail messages separate from other log entries
| for simpler reading. Otherwise, the default channel will be used.
|
*/

'log_channel' => env('MAIL_LOG_CHANNEL'),

这是我的应用程序/邮件。景色是对的

use Queueable, SerializesModels;

/**
 * Create a new message instance.
 *
 * @return void
 */
public function __construct($details)
{
    $this->details = $details;
}

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->subject('Mail from Admin')
        ->view('email.sendmail');
}

这是我的控制器,已经添加了“使用App\email_atasan”

$form = Form::where('identifier', $identifier)->firstOrFail();
    DB::beginTransaction();

    try {
        $input = $request->except('_token');

        // check if files were uploaded and process them
        $uploadedFiles = $request->allFiles();
        foreach ($uploadedFiles as $key => $file) {
            // store the file and set it's path to the value of the key holding it
            if ($file->isValid()) {
                $input[$key] = $file->store('fb_uploads', 'public');
                $details = [
                    'title' => 'Name',
                    'body' => 'Please check this link'
                ];

                \Mail::to('myemail@domain')->send(new email_atasan($details));
            }

        }

        $user_id = auth()->user()->id ?? null;
        $form->submissions()->create([
            'user_id' => $user_id,
            'status' => 0,
            'content' => $input,
        ]);
        DB::commit();

        return redirect()
                ->route('formbuilder::form.feedback', $identifier)
                ->with('success', 'Form successfully submitted. Please wait');
    } catch (Throwable $e) {
        info($e);

        DB::rollback();

        return back()->withInput()->with('error', Helper::wtf());
    }

actually i dont know where should i add this code to my project
求你了,帮帮我

6gpjuf90

6gpjuf901#

听起来你没有像这样“处理队列”,请确保在终端中运行php artisan queue:workphp artisan queue:listen(如果你经常更改代码)。

wnavrhmk

wnavrhmk2#

检查这些解决方案:
1.您的电子邮件配置:检查您的电子邮件是less secureNot 2-steploged in和其更好地在浏览器中的一个标签中打开。
2.你正确地调用了那个动作吗?也许你的路线是错误的。
3.你使用Queue还是Event?如果答案是肯定的,那么检查你是否fire他们???

pes8fvy9

pes8fvy93#

你好,谢谢你的回答,我发现了问题。未阅读详细信息,所以我应该在App\mail中声明

public function build()
    {
        $detail=$this->details;
        return $this->subject('Mail from Admin BPPT')
            ->view('email.sendmail', compact('detail'));
    }
c0vxltue

c0vxltue4#

我在搜索“Laravel Mandrill没有错误没有电子邮件”时遇到了这个问题
这看起来很明显,但是如果你的发件人地址没有在你的config/mail.php中配置,那么Mandrill将拒绝邮件,它不会发送,但是不会以允许/鼓励Laravel告诉你的方式抛出错误。
你会期望一个“山魈拒绝了你的邮件-没有从地址”,你会去doh我忘记设置了。在我的情况下,我的注册表去是的,工作-我们已经向您发送了一封验证电子邮件-当它没有。
希望这对其他人有帮助。

w8ntj3qf

w8ntj3qf5#

您应该添加:* 'local_domain' => env('MAIL_HOST')在配置文件'config/mail.php'中。
不要忘记清理配置缓存
php artisan config:clear
*

相关问题