SMTP for PHPMailer class

PHPMailer What is SMTP
Simple Mail Transfer Protocol (SMTP) is widely used internet protocol to manage mail. You have already seen how PHPMailer is installed and used to send mail. We will learn how to send mail using PPHPMailer through SMTP.

For testing the script in your host, it is always better you take one email account by pointing MX record to your hosting account. If you are hosting your mail account in other servers ( other than your own hosting server ) they check that your host is allowing to use other SMTP server or not.

In our previous example we have seen how we included the class and created mail object. Now to test SMTP with PHPMailer we will included another file which will also load our required SMTP classes.
The included file PHPMailerAutoload.php is part of the zip file you have downloaded and installed to use PHPmailer class. All details are explained in our previous tutorial on PHPMailer.

Host address.

Your host will provide you with the address of its SMTP server. It can be one of the following address.

For Hostgator :
For : allows by using localhost as host name, try using localhost if you are a godaddy customer.

$bodytext=' Hi this is my body text ';
echo $bodytext;
$subject= ' Message Subject'.date(" H:i:s", time());
echo "<br> $subject <br>";

$email = new PHPMailer();
$email->Host = localhost;// Try your mail host address
//$email->Host = "";
$email->Port = 25;
$email->SMTPAuth = false;
$email->SMTPSecure = false;
$email->Username = "";
$email->Password = "yourpassword";

$email->From      = '';
$email->FromName  = 'Your name here';
$email->Subject   = $subject;

$email->Body      = $bodytext;

//$file_to_attach = 'templates/top.php';

//$email->AddAttachment( $file_to_attach,'Your file here');

    echo "Mailer Error: " . $email->ErrorInfo;
    echo "Message has been sent successfully";
PHP Mail PHPMailer class PHPMailer class using SMTP Sending Multiple Mails
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer