LoginSignup
2
3

More than 3 years have passed since last update.

Send Mail from laravel using SMTP on XSERVER

Last updated at Posted at 2020-03-15

Environment

MAIL_DRIVER=smtp   
MAIL_HOST=sv[YOUR_NUM].xserver.jp           
MAIL_PORT=587
MAIL_USERNAME=[YOUR_MAIL]
MAIL_PASSWORD=[PASSWORD_FOR_YOUR_MAIL]
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=[ADDRESS_YOU_WANT]
MAIL_FROM_NAME=[ANYTHING_YOU_WANT]

※Domain name of MAIL_FROM_ADDRESS have to be same as MAIL_HOST.

Controller


<?php                                                                                                                                                                                                                                     

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Mail;

class SendmailController extends Controller
{
    public function sendMail() 
    {   
        Mail::send('mail', array(), function($message){
            $message->to('address@example.com', 'Title')->subject('Test mail');
        }); 
    }   
}

SPF Record

If you can't send mail from xserver, please check your spf record on xserver.

CAUTION

If you put your server without Japan.
You need to change setting like below.

Artboard.png

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3