Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
titlePHP - Sending email using SMTP+
linenumberstrue
<?php
//########################################################
//Include the PHPmailer class.                 
//
//PHPmailer allows you to create and  transport an email an email message.                   
//The PHPmailer class is available at this address:
//https://github.com/PHPMailer/PHPMailer/ 
//########################################################
require_once "class.phpmailer.php";
$EmailMessage = new PHPmailer(); 
$EmailMessage->SetLanguage('en','language/'); 	//Define the language

//**********************************************
//SMTP configuration
//**********************************************
$EmailMessage->IsSMTP();      	//Specify usage of SMTP Server
$EmailMessage->Host = "in.smtpok.com"; 	//SMTP+ Server address 
$EmailMessage->Port="25";   	//SET the SMTP Server port               
$EmailMessage->Username = "smtpplus_username";    	//SMTP+ authentication: username 
$EmailMessage->Password = "smtpplus_password";    	//SMTP+ authentication: password       
$EmailMessage->SMTPAuth = true;    	//Authentication required

//**********************************************
//Email data
//**********************************************
$EmailMessage->IsHTML(true); 	//Set the email format
$EmailMessage->FromName= "myname"; 	//From: display name
$EmailMessage->From="sender_address@domain.com"; 	//From: email address
$EmailMessage->AddAddress("recipient_address@domail.com");       	//Add one or more recipients
$EmailMessage->Subject="My first email sent via SMTP+"; 	//Set the email subject
$EmailMessage->Body="<b>Hello,<b><br/>This is my first email.";      	//Set the email body
$EmailMessage->AltBody="Hello, This is my first email..";	//Set the email text part
 
//**********************************************
//Send the email
//**********************************************
if(!$EmailMessage->Send())
{ 
echo "<h1>Error sending the email.</h1>"; 	//Email was not sent
}
else
{
echo "Email has been sent"; 	//Mail sent
}                             

?>