PHPMailer settings for correct email sending

PHPMailer settings for HostBrook and GoDaddy email servers
Written by Admin Last update: May. 12, 2023
PHPMailer

HostBrook recommends using PHPMailer for email sending from PHP.
Please see below PHPMailer settings and PHP code example that works on our servers.

PHPMailer project at GitHub.

Summary of this page:

PHPMailer settings for cPanel email server

$mail->isSMTP();
$mail->Host = 'xxxxxxxNNNNN.prod.iad2.secureserver.net';
$mail->SMTPSecure = 'SSL';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'mail@mydomain.com';
$mail->Password = 'EMAILPASSWORD';

Replace xxxxxxxNNNNN with your correct ID that you can find in the address bar while login in cPanel

Important (!): If you use cPanel email accounts to send emails via PHPMailer, be sure email routing set to LOCAL.

PHPMailer settings for Professional Email (OX Drive)

$mail->isSMTP();
$mail->Host = 'smtpout.secureserver.net';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'your@email';
$mail->Password = 'EMAILPASSWORD';

Important (!): If you use Professional email accounts to send emails via PHPMailer, be sure email routing set to REMOTE.

How to add DKIM signature

Although GoDaddy doesn't provide DKIM signature option for both cPanel and Workspace emails (this option is available for Microsoft 365 email plan only) you still can send emails with DKIM signature using PHPMailer as an email sender. This can decrease the probability to get your emails into the spam box.

If you would like to add DKIM signature to your emails that sent via PHPMailer, please follow the steps below.

Example of PHP code

The PHP code below uses cPanel email server settings and DKIM signature.
Just replace values in {} brackets with your data to make it work:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require_once '/PHPMailer/Exception.php';
require_once '/PHPMailer/PHPMailer.php';
require_once '/PHPMailer/SMTP.php';

$mail = new PHPMailer(true);

$mail->isSMTP();
$mail->Host = '{xxxxxxxNNNNN}.prod.iad2.secureserver.net';
$mail->SMTPSecure = 'SSL';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = '{EMAIL_FROM}';
$mail->Password = '{EMAIL_PASSWORD}';

$mail->DKIM_domain = '{DOMAIN_NAME}';
$mail->DKIM_selector = '{SELECTOR}';
$mail->DKIM_identity = '{EMAIL_FROM}';
$mail->DKIM_private_string = '-----BEGIN RSA PRIVATE KEY-----
{PRIVATE_KEY}
-----END RSA PRIVATE KEY-----';

$mail->isHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Encoding = 'base64';

$mail->setFrom('{EMAIL_FROM}', '{NAME_FROM}');
$mail->Subject = '{MAIL_SUBJECT}';
$mail->addAddress('{EMAIL_TO}', '{NANE_TO}');
$mail->Body = '{EMAIL_HTML_BODY}';
$mail->AltBody = '{EMAIL_PLAIN_TEXT_BODY}';

try {
    $mail->send();
    // Message has been sent successfully

} catch (Exception $e) {
    // Error occurred during email sending
    echo 'Error occurred: '.$mail->ErrorInfo;

}

DKIM for WordPress Mailer

By default WordPress mailer works with PHPMailer like with PHP mailer what can occur to delivery issues. To prevent it you need to set-up SMTP settings using some plugin or just easly modify functions.php file of your template by adding PHPMailer custom initialization. Here is an example of how to add server and DKIM settings for GoDaddy/HostBrook accounts:

add_action( 'phpmailer_init', 'phpmailer_config' );
function phpmailer_config( $phpmailer ) {

  // Server settings
  $phpmailer->isSMTP();
  $phpmailer->Host = '{xxxxxxxNNNNN}.prod.iad2.secureserver.net';
  $phpmailer->Port = '587';
  $phpmailer->SMTPSecure = 'SSL';
  $phpmailer->SMTPAuth = true;
  $phpmailer->Username = '{EMAIL_FROM}';
  $phpmailer->Password = '{EMAIL_PASSWORD}';
  $phpmailer->From = '{EMAIL_FROM}';
  $phpmailer->FromName = '{NAME_FROM}';

  // DKIM settings
  $phpmailer->Encoding = 'quoted-printable';
  $phpmailer->DKIM_domain = '{DOMAIN_NAME}';
  $phpmailer->DKIM_selector = '{SELECTOR}';
  $phpmailer->DKIM_passphrase = '';
  $phpmailer->DKIM_identity = $phpmailer->From;
  $phpmailer->DKIM_private_string =
  '-----BEGIN RSA PRIVATE KEY-----
  {PRIVATE_KEY}
  -----END RSA PRIVATE KEY-----';
}

Was this article helpful?

Related articles