问题
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] production.ERROR: ErrorException: mkdir(): No such file or directory in /var/www/html/jbservice/vendor/swiftmailer/swiftmailer/lib/classes/Swift/KeyCache/Disk$ Stack trace: #0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'mkdir(): No suc...', '/var/www/html/j...', 273, Array) #1 /var/www/html/jbservice/vendor/swiftmailer/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php(273): 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