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.
require_once('my_phpmail/PHPMailerAutoload.php');
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 : mail.yourdomain.com
For godaddy.com : relay-hosting.secureserver.net

Godaddy.com allows by using localhost as host name, try using localhost if you are a godaddy customer.
<?php

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

require_once('my_phpmail_folder/PHPMailerAutoload.php');
$email = new PHPMailer();
$email->isSMTP();
$email->Host = localhost;// Try your mail host address
//$email->Host = "relay-hosting.secureserver.net";
$email->Port = 25;
$email->SMTPAuth = false;
$email->SMTPSecure = false;
$email->Username = "userid@example.com";
$email->Password = "yourpassword";


$email->From      = 'userid@example.com';
$email->FromName  = 'Your name here';
$email->Subject   = $subject;

$email->Body      = $bodytext;
$email->AddAddress('name@example.com');
$email->AddAddress('name@example.com');

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

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

if(!$email->send()) 
{
    echo "Mailer Error: " . $email->ErrorInfo;
} 
else 
{
    echo "Message has been sent successfully";
}
?>
PHP Mail PHPMailer class PHPMailer class using SMTP Sending Multiple Mails
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com











    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 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer