PHP: Sending E-mail with PHPMailer and SMTP


Read first: PHP: Sending E-mail with Gmail SMTP and PHPMailer

We can send email with Gmail SMTP but Google limit number of email per day: you can see the limitation of Gmail SMTP here

With a VPS, we can send unlimited emails through our SMTP server

REQUIREMENT:
* A VPS linux, and KLOXO installed
* Own domain name ex: tutorialspots.com

STEP 1:
Point 2 subdomains (mail and webmail) to IP of VPS

STEP 2:
loginto your kloxo control panel (IP:7778) with admin account: go to Server Mail Settings

Fill out 2 fields:
My Name: yourdomain.com
Additional Smtp Port: 587

STEP 3:
Go to your DOMAIN and go to Mail Accounts

Create your own email account:

STEP 4: go to Webmail Application and chose your webmail application ex: RoundCube

STEP 5:
Restart your vps, now, you can login webmail to use your new email. You can read RoudCube: how to save a draft email to know more about ROUNDCUBE webmail

STEP 6:
We can use smtp to send email

<?php

//error_reporting(E_ALL);
error_reporting(E_STRICT);

date_default_timezone_set('Asia/Saigon');

require_once('PHPMailer/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();
$body             = 'Welcome to TUTORIALSPOTS.COM';
 

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.tutorialspots.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "mail.tutorialspots.com"; // sets the SMTP server
$mail->Port       = 587;                    // set the SMTP port for the GMAIL server
$mail->Username   = "tutorialspots@tutorialspots.com"; // SMTP account username
$mail->Password   = "your pass";        // SMTP account password

$mail->SetFrom('tutorialspots@tutorialspots.com');

$mail->AddReplyTo("victim@gmail.com");

$mail->Subject    = "Welcome to TUTORIALSPOTS.COM";
 
$mail->MsgHTML($body);

$address = "victim@gmail.com";
$mail->AddAddress($address);
 

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

?>

Result:
SMTP -> FROM SERVER:220 tutorialspots.com - Welcome to Qmail ESMTP
SMTP -> FROM SERVER: 250-tutorialspots.com - Welcome to Qmail 250-STARTTLS 250-PIPELINING 250-8BITMIME 250-SIZE 20971520 250 AUTH LOGIN PLAIN CRAM-MD5
SMTP -> FROM SERVER:250 ok
SMTP -> FROM SERVER:250 ok
SMTP -> FROM SERVER:354 go ahead
SMTP -> FROM SERVER:250 ok 1376491897 qp 1153
Message sent!

Leave a Reply