Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. <?php
  2.     /**
  3.      * Questo file definisce le funzione da utilizzare per spedire email dall'indirizzo
  4.      * settato nel file config.inc.php.
  5.      * Viene utilizzato l'oggetto creato tramite Mail::factory.
  6.      */
  7.    
  8.     require_once('Mail.php');       // FILE DELLA CLASSE Mail::Factory del modulo Mail di PEAR
  9.         }
  10.    
  11.     /**
  12.      * Invia un email ai destinatari specificati.
  13.      * Params:
  14.      *      1. $to => contiene il/i destinatari della mail
  15.      *      2. $subject => contiene l'oggetto della mail
  16.      *      3. $message => contiene il messaggio della mail
  17.      * Returns:
  18.      *      true nel caso non ci siano errori, un oggetto PEAR_Error altrimenti.
  19.      */
  20.     function send_mail($to, $subject, $message) {
  21.         /* mail's setup */
  22.         $from = "STAGE SYSTEM - ISIS GAZZADA <".$SMTP_USER.">";
  23.         $subject = $subject;
  24.         $finalMessage = $message."\nMessaggio inviato da STAGE-SYSTEM il ".date('d-m-y')." alle ".date('H:i:s')."\n";
  25.         $body = $finalMessage;
  26.  
  27.         /* smtp's setup */
  28.         $host = SMTP_HOST;
  29.         $port = SMTP_PORT;
  30.         $username = SMTP_USER;
  31.         $password = SMTP_PASSWORD;
  32.    
  33.         $headers = array ('From' => $from,
  34.            'To' => $to,
  35.            'Subject' => $subject);
  36.         $smtp = Mail::factory('smtp',
  37.             array ('host' => $host,
  38.              'port' => $port,
  39.              'auth' => true,
  40.              'username' => $username,
  41.              'password' => $password));
  42.  
  43.         $mail = $smtp->send($to, $headers, $body);
  44.        
  45.         if (PEAR::isError($mail)) {
  46.             return false;
  47.         }
  48.         else {
  49.             return true;
  50.         }
  51.     }
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement