Sending Emails with Swift Mailer

This post shares insights on creating and sending emails using Swift Mailer. To know more about the topic, feel free to check Send Emails with Swift Mailer from PHP Apps

Swift Mailer is easy to use with any PHP framework. To send messages, you can integrate Swift Mailer into popular sending providers like Sendgrid and similar as well as external SMTP servers.

Swift Mailer is used as the main mail option in frameworks like Yii2 and CMS like Drupal, Laravael’s email API is built on top of the Swift Mailer library as well.

To install Swift Mailer, we need to use Composer:

$ composer require "swiftmailer/swiftmailer:^6.0

Correspondingly, to create transport, we need hostname, port, username, and password

Making an email

In Swift Mailer, messages are composed with the help of Swift_Message class.

Let’s start by creating a message from top to bottom, likely to an email client: set recipient, sender, and a subject. Usually, we will make it with setSubject(), setTo(), and setFrom() methods.

To include several recipients, use an array and to add recipients in copy, use setCc() or setBcc(). You can set name headers with associative arrays. Also, you can embed images and attachments into our email, which is explained in the guide.

For more details and alternatives, refer to the corresponding section in the Swift Mailer documentation.

Sending an email

Before sending, you have to ensure that all the required transport data is set. For example, if you are going to test emails prior to sending, you should use the Mailer class to send the message with all the credentials of your testing tool. In our case, it is Mailtrap.


This message can be send with Swift Mailer:
This is image title


 try {
$transport = (new Swift_SmtpTransport('', 2525))
    $mailer = new Swift_Mailer($transport);
public function index($name, \Swift_Mailer $mailer)
 $message = (new Swift_Message())
 ->setSubject('Here should be a subject')
 ->setTo(['' => 'New Mailtrap user'])
'' => 'Product manager'
'<html>' .
' <body>' .
'  <img src="' .
     $message->embed(Swift_Image::fromPath('image.png')) .
   '" alt="Image" />' .
'  <p>Welcome to Mailtrap!</p>’.
‘Now your test emails will be <i>safe</i>’ .
' </body>' .
$message->addPart('Welcome to Mailtrap, now your test emails will be safe', 'text/plain');

#symfony #php

What is GEEK

Buddha Community

Sending Emails with Swift Mailer

Sending Email in Asp Net Core MVC 5 using Quick Mailer

#sending email in asp net core mvc 5 using quick mailer #sending email in asp net core #sending email in c#

Send Email In Laravel

Hello Guys,

Today I will give you demo how to send email in laravel, in this post we will show how to send email using SMTP in laravel, email is very basic and most important feature in web development field and it is necessary for all client.

So, in this tutorial I will give you information about send mail in laravel. So, follow below steps.

Send Email In Laravel

#laravel #php #send email in laravel #email #how to send email in laravel #laravel send mail

Houston  Sipes

Houston Sipes


10 Free Online Resources To Learn Swift Language

Swift is a fast and efficient general-purpose programming language that provides real-time feedback and can be seamlessly incorporated into existing Objective-C code. This is why developers are able to write safer, more reliable code while saving time. It aims to be the best language that can be used for various purposes ranging from systems programming to mobile as well as desktop apps and scaling up to cloud services.

Below here, we list down the 10 best online resources to learn Swift language.

(The list is in no particular order)

#developers corner #free online resources to learn swift language #learn swift #learn swift free #learn swift online free #resources to learn swift #swift language #swift programming

I am Developer


Node js Send Email with Attachment using Nodemailer

In this node js send email with attachment using nodemailer. In this tutorial, you will learn how you can send the email using the Gmail SMTP in node js. Here you will learn step by step, how you can send email using Gmail SMTP in node js

Sending email via Node js is easy. Today we are going to discuss send an email via node js. We will use nodemailermodule and Gmail SMTP to send the email. We will also learn how to send an email with an attachment. So let’s get started with the node js send email with attachment tutorial.

How to Send Attachment in Email using Nodemailer in Node Js

Just follow the following steps and send email through gmail with attachment using nodemailer in node js:

1. Step 1 - First Install Nodemailer 1. Step 2 - Configure Gmail SMTP with Nodemailer 1. Step 3 - Sending Email with Gmail SMTP 1. Step 4 - Send Multiple Recipient At The Same Time 1. Step 5 - Send Simple HTML

#node js send email through gmail with attachment #how to send attachment in mail using nodemailer #nodejs send email with attachment #nodejs send email with attachment example

August  Larson

August Larson


Send emails through Python

You will be surprised how easy is to configure your account and send emails with attachments in Python

You cannot imagine how easy and simple it is to configure your email account to be able to send emails to one or several contacts directly from your Python environment without any effort or complicated code.

In this article, I will walk you through the process. All you need is a Gmail account and your Python running and ready to go. Let me show you how it’s done.

#email #python #programming #automation #send-email #send emails through python