Error throwing while sending an email using laravel [closed]

徘徊边缘 提交于 2021-01-26 03:14:07

问题


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.

enter image description here

Relevant error description edited in from comments:

[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'); });

回答1:


You can check your log.

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

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');
    }
}

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



来源:https://stackoverflow.com/questions/48440342/error-throwing-while-sending-an-email-using-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!