Skip to main content

Send Mail Using PhpMailer

Hello,

    Right not it is common for sending mail for every site for subscription, registration etc.
Here I have explain you how to send mail using Phpmailer.
It is very easy you nee to only two file
1 ) class.smtp.php
2) class.phpmailer.php

From the below given link you can download above two files
Download phpmailer library

After downloading this two files make one new file "phpmailer.php" and put below code.

Using only two files your work done.
Here i write one function for sending mail using it you can send mail.

<?php 
function sendEmailAddress($to, $subject, $message)
{
 require_once("class.phpmailer.php");
 $mail = new PHPMailer(); // create a new object
 $mail->IsSMTP(); // enable SMTP
 $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
 $mail->SMTPAuth = true; // authentication enabled 
 $mail->SMTPSecure = 'tls';
 
 $mail->Host = "SMTP HOST NAME";
 $mail->Port = 587; // or 25

 $mail->IsHTML(true);
 $mail->Username = 'SMTP USER NAME';
 $mail->Password = 'SMTP PASSWORD';

 $mail->SetFrom('FROM NAME','your site name or any other which you want to display');
 $mail->AddReplyTo('REPLY To', 'your site name or any other which you want to display');
 $mail->Subject = $subject;
 $mail->Body = $message;
 $mail->AddAddress($to);
 $result = true;
 if(!$mail->Send()){
  echo "Mailer Error: " . $mail->ErrorInfo;
  $result = false;
 }
 return $result;  
}
sendEmailAddress($to,'Test Subject','Test Message');
?>

Comments

Popular posts from this blog

$var = 'PHP Tutorial'. Put this variable into the title section, h3 tag and as an anchor text within a HTML document.

$var = 'PHP Tutorial'. Put this variable into the title section, h3 tag and as an anchor text within a HTML document.  <?php echo "<html>"; echo "<head>"; echo "<title>"; echo "PHP TUTORIAl"; echo "</title>"; echo "<body>"; echo "<h3>PHP TUTORIAL</h3>"; echo "<hr>"; echo "<p>PHP, an acronym for Hypertext Preprocessor, is a widely-used open source general-purpose scripting language. It is a cross-platform, HTML embedded server-side scripting language and is especially suited for web development.</p>"; echo "</body>"; echo "</head>"; echo "</html>"; ?> Output:

Create a simple HTML form and accept the user name and display the name through PHP echo statement.

Create a simple HTML form and accept the user name and display the name through PHP echo statement. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Post Data</title> </head> <body> <form method="POST" action=""> <label>Enter First Name</label> <input type="text" name="firstname" id="firstname" /> <input type="submit" name="submit_button" value="Submit Name" /> </form> </body> </html> <?php if(isset($_POST) && !empty($_POST)) { echo "<h3> Hello ".$_POST['firstname']."</h3>"; } ?> Output:

Write a PHP script, which change the color of first character of a word.

Write a PHP script, which change the color of first character of a word. <?php   $text = 'PHP Tutorial';   $text = preg_replace('/(\b[a-z])/i','<span style="color:red;">\1</span>',$text);   echo $text;   ?>