Tuesday, 25 August 2015

php-pear-mai-tutorial

01:41

(1)first download  pear package to send email  following link is given:

https://pear.php.net/package/PEAR/download


& find Mail.php  file

(2)find code for sending email with  smtp setting details  save this file name by email.php  under same  folder where Mail.php file is stored run it :


<?php

require_once "Mail.php";

    $from = "youremailid@gmail.com";
 
    $to = "omchandmaurya1@gmail.com";
 
    $subject = "Hi!";
 
    $body = "Hi,\n\nHow are you?";
 

    $host = "ssl://smtp.gmail.com";
 
    $port = "465";
 
    $username = "youremailid@gmail.com";
 
    $password = "yourpassword";
 

    $headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);
    $smtp = Mail::factory('smtp',
      array ('host' => $host,
        'port' => $port,
        'auth' => true,
        'username' => $username,
        'password' => $password));

    $mail = $smtp->send($to, $headers, $body);

    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
    } else {
      echo("<p>Message successfully sent!</p>");
    }


?>


Php   Mail   function :
<?php

   $to = "omchandmaurya1@gmail.com";
  
 
   $subject = "This is subject";
  
 
   $message = "This is simple text message.";
  
 
   $header = "From:omnetworkom@gmail.com \r\n";
  
 
   $retval = mail ($to,$subject,$message,$header);
  
 
   if( $retval == true ) 
 

   {

      echo "Message sent successfully...";

   }

   else

   {

      echo "Message could not be sent...";

   }

?>


Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

1 comments:

PHP Training Mumbai, PHP MySQL Training Mumbai, PHP Course Mumbai, PHP Institute Mumbai

 

© 2013 PHP TRAINING IN MUMBAI BY OM SIR . All rights resevered. Designed by OM SIR

Back To Top