首页 > 解决方案 > laravel 无法发送电子邮件,也不是错误

问题描述

我一直在做一个项目 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());
    }

实际上我不知道我应该在哪里将此代码添加到我的项目中

请帮我

标签: phplaravelemailsmtpformbuilder

解决方案


我在搜索“laravel mandrill no error no email”时遇到了这个问题

这似乎很明显,但如果您的发件人地址未在您的 config/mail.php 中配置,那么 Mandrill 将拒绝邮件并且它不会发送,但不会以允许/鼓励 Laravel 告诉的方式抛出错误你关于它。

你会期待“Mandrill 拒绝了你的邮件 - 没有来自地址”,你会去,我忘了设置它。就我而言,我的注册表单是有效的——我们已经向您发送了一封验证电子邮件——但它没有。

希望这对其他人有帮助。


推荐阅读