Home Case Studies Technology

Sending Zoho emails via SMTP using PHP Swiftmailer

Author Image

Rahul Matharu

29 Jul, 2021 · 1 min read
Article Thumbnail

The aim of this tutorial is to quickly show how Zoho Email can be used in your PHP code to send emails.

There is also a quick video explaining this:

The code is as follows:

class ZohoEmail
   public $toEmail = '[email protected]';
   public $subject = 'Test subject';
   public $body = 'Test message';
   public $host = 'smtp.zoho.in';//Country specific
   public $port = '587';
   public $encryption = 'tls';
   public $username = '[email protected]';
   public $password = 'YourZohoPassword';
   public $fromName = 'Your Name';
   public $fromEmail = '[email protected]';

   public function actionEmail(){
       $transport = (new Swift_SmtpTransport($this->host, $this->port))

       $mailer = new Swift_Mailer($transport);

       $message = (new Swift_Message($this->subject))
           ->setFrom([$this->fromEmail => $this->fromName])
           ->setBody($this->body, 'text/html');


Documentation that helped


The forum thread regarding the correct SMTP Server


Special cases (2 Factor Authentication on)


Author Image

Rahul Matharu