PHPMailer settings for correct email sending

PHPMailer settings for HostBrook and GoDaddy email servers
Written by Admin Last update: Dec. 22, 2020
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 = 'your@email';
$mail->Password = 'EMAILPASSWORD';

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

PHPMailer settings for Workspace email server

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

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;

}

Was this article helpful?

Related articles