Log In

Step 1

PHPMailer is a full featured email transfer class for PHP that exposes a much greater range of features than the standard PHP mail() function.

Firstly, download PHPMailer from here and extract it into your desired location.

Go to the extracted folder and copy following files to your web server root directory:

PHPMailer.php
Exception.php
SMTP.php

Step 2

PHPMailer Script to Send Email Using SMTP Authentication

Adjust the example below for your needs. Make sure you assigned values to the following variables:

  • From: the sender’s email address.
  • FromName: the sender’s name.
  • AddAddress: the recipient’s email address and name.
  • AddReplyTo: the reply-to email address and name.
  • Username: your SMTP username.
  • Password: your SMTP password.

Create a file called smtp2go.php under the root folder of your web server with this content:

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require("Exception.php");
require("PHPMailer.php");
require("SMTP.php");

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->Host = "mail.smtp2go.com";
$mail->Port = "2525"; // 8025, 587 and 25 can also be used. Use Port 465 for SSL.
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = "smtp_username";
$mail->Password = "smtp_password";

$mail->From = "sender@example.com";
$mail->FromName = "Susan Sender";
$mail->AddAddress("recipient@example.com", "Rachel Recipient");
$mail->AddReplyTo("Your Reply-to Address", "Sender's Name");

$mail->Subject = "Hi!";
$mail->Body = "Hi! How are you?";
$mail->WordWrap = 50;

if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
exit;
} else {
echo 'Message has been sent.';
}
?>

Step 3

Test the smtp2go.php page using browser and see if the email is sent successfully. We recommend that the SMTP Username and SMTP Password are stored outside the root folder of the web server.

Please note: if you experience “timeouts” or problems connecting due to an unreliable internet connection, consider increasing the max_execution_time setting in the php.ini file on your server, to a value such as 120 (instead of the default value 30).

Ready for better email delivery?

Try SMTP2GO free for as long as you like:

Try SMTP2GO Free → Paid plans available for over 1,000 emails/month.