This question already asked but that not solving my issue.
Am trying to send email in my laravel
project. But i got error message like
Swift_TransportException: Connection could not be established with host mailtrap.io [Connection timed out #110] in file /home/bala/git/mobile-api/modules/jobs/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php on line 269
This is my code:
.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>
I tried this question answer but i not solve my issue.
Thanks in advance..!