这个问题已经问了,但不能解决我的问题。
正在尝试在我的laravel
项目中发送电子邮件。但是我收到了类似的错误消息
Swift_TransportException:无法使用文件/ home / bala / git / mobile-api / modules / jobs / vendor / swiftmailer / swiftmailer / lib / classes / Swift中的主机mailtrap.io [连接超时#110]建立连接/Transport/StreamBuffer.php在第269行
这是我的代码:
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mygmail@gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
AppJobsController.php
<?php
namespace App\Http\Controllers\Jobs;
require app_path().'/../../../lib/vendor/autoload.php';
include_once(app_path().'/../../../lib/utils.php');
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Routing\ResponseFactory;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Input;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\View;
use App\Models\Jobs\JobExperience;
use App\Models\Jobs\JobSalary;
use App\Models\Jobs\JobTitle;
use App\Models\Jobs\JobDetails;
use App\Models\Jobs\JobApply;
use App\Models\Jobs\ModuleItems;
use Illuminate\Http\Response;
use Illuminate\Http\Request;
use Carbon\Carbon;
use Validator;
use Config;
use File;
use DB;
use Mail;
class AppJobsController extends Controller
{
public function jobApply(Request $request)
{
$JobApply = new JobApply;
$JobApply->job_id = $request->job_id;
$JobApply->attachment = $images[0];
$JobApply->user_id = $this->user['uid'];
if ($JobApply->save())
{
$jobDetails = JobDetails::find($request->job_id);
$JobTitle = JobTitle::find($jobDetails->jobtitle_id);
$content = array(
'JobTitle' => $JobTitle->title,
'CompanyName' => $jobDetails->company_name,
'postedDate' => date('d-m-Y', strtotime($jobDetails->created_at)),
'user' => 'App User'
);
$subject = 'Applying For '.$JobTitle->title;
$toUser = $jobDetails->email_id;
$pathToFile = $this->uploadlocation.'/'.$images[0];
Mail::send('email.sendResumes', $content, function ($message) use ($pathToFile, $toUser, $subject)
{
$message->from('noreply@gmail.com', 'Job Appy');
$message->subject($subject);
$message->to($toUser);
});
}
}
}
email.sendResumes
<div>
I would like to apply for {{$JobTitle}} within your company {{$CompanyName}}, adversited in Thedal on {{$postedDate}}.<br><br>
I believe this position would provide a great opportunity to further my chosen career. My willingness to work hard and build my skill base will make me a good candidate for the job.<br><br>
I look forward to hearing from you at your convenience.<br><br>
Thanks & Regards,<br><br>
{{$user}}
</div>
我尝试了这个问题的答案,但我没有解决问题。
提前谢谢..!
答案 0 :(得分:1)
我认为您应该重新启动服务器。
答案 1 :(得分:1)
配置 gmail 的步骤:
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your@gmail.com
MAIL_PASSWORD=apppassword
MAIL_ENCRYPTION=tls
有关应用程序密码,请阅读“ How to generate an App password:”部分
完成.env
编辑后,请在您的终端中输入以下命令以清除缓存:
php artisan config:cache