Thursday, 19 December 2013

Sending e-mail using SMTP server of Gmail with PHP.

Sending e-mail using SMTP server of Gmail with PHP. This article is about send emails in SMTP(Simple Mail Transfer Protocol) using phpmailer by gmail server,
Here we are using PHPMailer for send emails using SMTP in php
It is very easy process.....

Now Create File Name as "Demomail.php".
 $mail             = new PHPMailer();
 $mail->SMTPAuth   = true;                  // enable SMTP authentication
 $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
 $mail->Host       = "";      // sets GMAIL as the SMTP server
 $mail->Port       = 465;                   // set the SMTP port like to be 25, 80,465,587

 $mail->Username   = ""; // Sender GMAIL username
 $mail->Password   = "XXXXXXXX";            //Sender GMAIL password

 $mail->From       = "kc";
 $mail->FromName   = "Knowledge Corner";
 $mail->Subject    = "Demo mail";
 $mail->AltBody    = "This is the body when user views in plain text format"; //Text Body
 $mail->WordWrap   = 50; // set word wrap
            // body message you can place html code here
   $mail->MsgHTML("<b>This is first amil from KnowledgeCorner through SMTP</b>");
           //Attach a file here if any or comment this line,
           //reply-to address of your domain mail id and name
          //To address and name who will receive this email

   $mail->IsHTML(true); // send as HTML

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

Gmail is using SSL for security. for this you need to enable "extension=php_openssl.dll" in your php.ini file, if you are using ubuntu here you can go! the above gmail code will works in ubuntu without any php.ini modifications.

No comments:

Post a Comment