Using laravel 5.7 with SwiftMailer library (SMTP to office365)
I have done my fair share of research and have not come across a problem like this. There are errors that I've seen and that were somewhat like this one, but they all made sens to me unlike this one.
I have no clue how to fix this and would love a second hand on this.
Error return:
fwrite(): SSL: The operation completed successfully.
config/mail.php has all the configuration as it should be:
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.office365.com'),
'port' => env('MAIL_PORT', 587), //office 365 need to use 587
'encryption' => env('MAIL_ENCRYPTION', 'tls'), //office 365 need to use TLS
'username' => env('xxxx@xxxxxxx.xx'),
'password' => env('xxxxxxxxx'),
.env also has its configuration sorted out correctly:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587 //office 365 need to use 587
MAIL_USERNAME=xxxx@xxxxxxx.xx
MAIL_PASSWORD=xxxxxxxxx
MAIL_ENCRYPTION=tls //office 365 need to use TLS
postContact function in Controller
public function postContact(Request $request) {
//validation
$this->validate($request, [
'companyName' => 'required',
'name' => 'required',
'email' => 'required|email',
'phone' => 'numeric',
'message' => 'min:10']);
//request data from submitted form
$data = array(
'companyName' => $request->companyName,
'name' => $request->name,
'email' => $request->email,
'phone' => $request->phone,
'bodyMessage' => $request->message
);
//send mail
Mail::send('emails.contact', $data, function($message) use ($data){
//$message->from($data['email']);
$message->to('xxxx@xxxxxxx.xx');
$message->subject('New email from xxxxxxxx');
});
return redirect('/'); }