使用Laravel发送电子邮件时抛出错误 [英] Error throwing while sending an email using laravel

查看:46
本文介绍了使用Laravel发送电子邮件时抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将Web应用程序迁移到新服务器后,使用laravel发送电子邮件时抛出错误.在以前的服务器上运行正常.

Error throwing while sending an email using laravel after migration the web application to a new server. It was working fine on the previous server.

从注释中编辑的相关错误描述:

Relevant error description edited in from comments:

[2018-01-25 13:31:10]生产.错误:ErrorException:mkdir():否此类文件或目录/var/www/html/jbservice/vendor/swiftmailer/swiftmailer/lib/c‌lasses/Swift/KeyCach‌e/Disk $堆栈跟踪:#0 [内部函数]:照亮\ Foundation \ Bootstrap \ HandleExceptions-> handleErro‌r(2,'mkdir():不成功...','/var/www/html/j ...',273,数组)#1/var/www/html/jbservice/vendor/swiftmailer/swiftmailer/lib/c‌lasses/Swift/KeyCach‌e/DiskKeyCache.php(2‌73):mkdir('/tmp/68d392a3e3 ...')

[2018-01-25 13:31:10] production.ERROR: ErrorException: mkdir(): No such file or directory in /var/www/html/jbservice/vendor/swiftmailer/swiftmailer/lib/c‌​lasses/Swift/KeyCach‌​e/Disk$ Stack trace: #0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleErro‌​r(2, 'mkdir(): No suc...', '/var/www/html/j...', 273, Array) #1 /var/www/html/jbservice/vendor/swiftmailer/swiftmailer/lib/c‌​lasses/Swift/KeyCach‌​e/DiskKeyCache.php(2‌​73): mkdir('/tmp/68d392a3e3...')

通过注释编辑的相关代码:

Relevant code edited from comments:

Mail::send('dashboard.emails.createticket', $data , function ($message) 
use ($data) { $message->subject('New Ticket: ' . $data['subject']) 
    ->to("atif@gmail.com") 
    ->from('HERE COMES THE SENDER EMAIL'); });

推荐答案

您可以检查您的日志.

如果显示SwiftMailer试图在默认的/tmp文件夹中创建缓存:

If it show the SwiftMailer was trying to create cache in default /tmp folder :

要解决此问题,请在app/Providers/AppServiveProvider.php的boot()方法中更改TMPDIR环境变量.

To solve the issue, change the TMPDIR environment variable in the boot() method of app/Providers/AppServiveProvider.php.

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    /**
     * Somehow PHP is not able to write in default /tmp directory and SwiftMailer was failing.
     * To overcome this situation, we set the TMPDIR environment variable to a new value.
     */
    if (class_exists('Swift_Preferences')) {
        \Swift_Preferences::getInstance()->setTempDir(storage_path().'/tmp');
    } else {
        \Log::warning('Class Swift_Preferences does not exists');
    }
}

请确保新的"tmp"文件夹位置可由Web服务器写入.

Please make sure that the new "tmp" folder location is writable by the web server.

这篇关于使用Laravel发送电子邮件时抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆