9951 explained code solutions for 126 technologies

phpmailerHow do I configure PHPmailer to use Zoho SMTP?

  1. Install the latest version of PHPmailer using composer by running the command composer require phpmailer/phpmailer
  2. Create a new instance of the PHPmailer class and set the SMTP host, username, and password for Zoho SMTP.
    $mail = new PHPMailer;
    $mail->Host = 'smtp.zoho.com';
    $mail->SMTPAuth = true;
    $mail->Username = '[email protected]';
    $mail->Password = 'password';
  3. Set the SMTP port, encryption, and authentication type.
    $mail->Port = 587;
    $mail->SMTPSecure = 'tls';
    $mail->SMTPAuthType = 'LOGIN';
  4. Set the sender and recipient information.
    $mail->setFrom('[email protected]', 'Mailer');
    $mail->addAddress('[email protected]', 'User');
  5. Set the subject and body of the message.
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
  6. Send the message and check for errors.
    if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
    echo 'Message has been sent';
  7. Output: Message has been sent

Helpful links

Edit this code on GitHub