Source for file mail.php

Documentation is available at mail.php

  1. <?php
  2.  
  3.  
  4. /**
  5. * Send an email to a specific address, using the Moodle system.
  6. * This function is heavily based on "email_to_user()" from Moodle's libraries.
  7. *
  8. @uses $CFG
  9. @uses $FULLME
  10. @param string $to The address to send the email to
  11. @param string $subject Plain text subject line of the email
  12. @param string $messagetext Plain text of the message
  13. @return bool Returns true if mail was sent OK, or false otherwise
  14. */
  15. function sloodle_text_email($to$subject$messagetext)
  16. {
  17.     global $CFG$FULLME;
  18.  
  19.     // Fetch the PHP mailing functionality
  20.     include_once($CFG->libdir .'/phpmailer/class.phpmailer.php');
  21.  
  22.     // We are going to use textlib services here
  23.     $textlib textlib_get_instance();
  24.  
  25.     // Construct a new PHP mailer
  26.     $mail new phpmailer;
  27.     $mail->Version 'Moodle '$CFG->version;           // mailer version
  28.     $mail->PluginDir $CFG->libdir .'/phpmailer/';      // plugin directory (eg smtp plugin)
  29.     // We will use Unicode UTF8
  30.     $mail->CharSet 'UTF-8';
  31.  
  32.     // Determine which mail system to use
  33.     if ($CFG->smtphosts == 'qmail'{
  34.         $mail->IsQmail();                              // use Qmail system
  35.         
  36.     else if (empty($CFG->smtphosts)) {
  37.         $mail->IsMail();                               // use PHP mail() = sendmail
  38.  
  39.     else {
  40.         $mail->IsSMTP();                               // use SMTP directly
  41.         if (!empty($CFG->debugsmtp)) {
  42.             echo '<pre>' "\n";
  43.             $mail->SMTPDebug true;
  44.         }
  45.         $mail->Host $CFG->smtphosts;               // specify main and backup servers
  46.  
  47.         if ($CFG->smtpuser{                          // Use SMTP authentication
  48.             $mail->SMTPAuth true;
  49.             $mail->Username $CFG->smtpuser;
  50.             $mail->Password $CFG->smtppass;
  51.         }
  52.     }
  53.  
  54.     // Use the admin's address for the Sender field
  55.     $adminuser get_admin();
  56.     $mail->Sender   $adminuser->email;
  57.     // Use the 'noreply' address    
  58.     $mail->From     $CFG->noreplyaddress;
  59.     $mail->FromName $CFG->wwwroot;
  60.  
  61.     // Setup the other headers
  62.     $mail->Subject substr(stripslashes($subject)0900);
  63.     $mail->AddAddress(stripslashes($to)'Sloodle' );
  64.     //$mail->WordWrap = 79; // We don't want to do a wordwrap
  65.     
  66.     // Add our message text
  67.     $mail->IsHTML(false);
  68.     $mail->Body $messagetext;
  69.  
  70.     // Attempt to send the email
  71.     if ($mail->Send()) {
  72.         $mail->IsSMTP();                               // use SMTP directly
  73.         if (!empty($CFG->debugsmtp)) {
  74.             echo '</pre>';
  75.         }
  76.         return true;
  77.         
  78.     else {
  79.         mtrace('ERROR: '$mail->ErrorInfo);
  80.         add_to_log(SITEID'library''mailer'$FULLME'ERROR: '$mail->ErrorInfo);
  81.         if (!empty($CFG->debugsmtp)) {
  82.             echo '</pre>';
  83.         }
  84.         return false;
  85.     }
  86. }
  87.  
  88.  
  89. /**
  90. * Send an email to an object in SL.
  91. *
  92. @param string $uuid The UUID of the object to send the email to
  93. @param string $subject Plain text subject line of the email
  94. @param string $messagetext Plain text of the message
  95. @return bool Returns true if mail was sent OK, or false otherwise
  96. */
  97. function sloodle_text_email_sl($uuid$subject$messagetext)
  98. {
  99.     return sloodle_text_email($uuid.'@lsl.secondlife.com'$subject$messagetext);
  100. }
  101.  
  102.  
  103. ?>

Documentation generated on Mon, 16 Jun 2008 15:56:42 +0100 by phpDocumentor 1.4.0