Laravel SMTP Setup

This guide provides a simple script to send out E-Mail using your smtp Account. You may refer theĀ Laravel Mail documentation for more options.

Also, please change the following variables in this guide:

  • Sender Name: the sender’s name.
  • the sender’s email address.
  • Recipient Name: the recipient’s name.
  • the recipient’s email address.
  • USERNAME: your SMTP username.
  • PASSWORD: your SMTP password.

Step 1

Make changes to the configuration file app/config/mail.php as below. For a secure TLS connection, you can also try using Port Number 25, 8025 or 587.

return array( 
 'driver' => 'smtp', 
 'host' => '', 
 'port' => 2525, 
 'from' => array('address' => '', 'name' => 'Sender Name'), 
 'encryption' => 'tls', 
 'username' => 'USERNAME', 
 'password' => 'PASSWORD', 
 'sendmail' => '/usr/sbin/sendmail -bs', 
 'pretend' => false, 

Step 2

Add the following code in your application to send the email:

$data = ['firstname' => 'Recipient Name'];
	Mail::send('example', $data, function($message)
    $message->to('', 'Recipient Name')->subject('Your Subject');

Here the example at Mail::send() method, is a view file located at app/views/ folder. A sample content of the app/views/example.php view file looks like below:

<!DOCTYPE html>
<html lang="en">
  <meta charset="UTF-8">
  <title>Example Template</title>	
    Hi, <?php echo $firstname; ?>
    This is a test message.

You may also like...

Leave a Reply