dokeos
[ class tree: dokeos ] [ index: dokeos ] [ all elements ]

Source for file mail.lib.inc.php

Documentation is available at mail.lib.inc.php

  1. <?php
  2. require(api_get_path(INCLUDE_PATH).'lib/phpmailer/class.phpmailer.php');
  3. require_once(api_get_path(INCLUDE_PATH).'/conf/mail.conf.php');
  4.  
  5.  //regular expression to test for valid email address
  6.  $regexp "^[0-9a-z_\.-]+@(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2,3})$";
  7.  
  8. /**
  9.  * Sends email using the phpmailer class
  10.  * Sender name and email can be specified, if not specified
  11.  * name and email of the platform admin are used
  12.  *
  13.  * @author Bert Vanderkimpen ICT&O UGent
  14.  *
  15.  * @param recipient_name       name of recipient
  16.  * @param recipient_email      email of recipient
  17.  * @param message           email body
  18.  * @param subject           email subject
  19.  * @return                  returns true if mail was sent
  20.  * @see                     class.phpmailer.php
  21.  */
  22. function api_mail($recipient_name$recipient_email$subject$message$sender_name=""$sender_email=""$extra_headers=""{
  23.  
  24.    global $regexp;
  25.    global $platform_email;
  26.  
  27.    $mail new PHPMailer();
  28.    $mail->Mailer  $platform_email['SMTP_MAILER'];
  29.    $mail->Host    $platform_email['SMTP_HOST'];
  30.    $mail->Port    $platform_email['SMTP_PORT'];
  31.  
  32.    if($platform_email['SMTP_AUTH'])
  33.    {
  34.       $mail->SMTPAuth 1;
  35.       $mail->Username $platform_email['SMTP_USER'];
  36.       $mail->Password $platform_email['SMTP_PASS'];
  37.    }
  38.  
  39.    $mail->Priority 3// 5=low, 1=high
  40.    $mail->AddCustomHeader("Errors-To: ".$platform_email['SMTP_FROM_EMAIL']."");
  41.    $mail->IsHTML(0);
  42.    $mail->SMTPKeepAlive true;
  43.  
  44.  
  45.    // attachments
  46.    // $mail->AddAttachment($path);
  47.    // $mail->AddAttachment($path,$filename);
  48.  
  49.  
  50.    if ($sender_email!="")
  51.    {
  52.       $mail->From           $sender_email;
  53.       $mail->Sender       $sender_email;
  54.       //$mail->ConfirmReadingTo = $sender_email; //Disposition-Notification
  55.    }
  56.    else
  57.     {
  58.       $mail->From         $platform_email['SMTP_FROM_EMAIL'];
  59.       $mail->Sender     $platform_email['SMTP_FROM_EMAIL'];
  60.       //$mail->ConfirmReadingTo = $platform_email['SMTP_FROM_EMAIL']; //Disposition-Notification
  61.     }
  62.  
  63.    if ($sender_name!="")
  64.    {
  65.       $mail->FromName $sender_name;
  66.    }
  67.    else
  68.    {
  69.       $mail->FromName $platform_email['SMTP_FROM_NAME'];
  70.    }
  71.       $mail->Subject $subject;
  72.       $mail->Body    $message;
  73.       //only valid address
  74.       if(eregi$regexp$recipient_email ))
  75.       {
  76.           $mail->AddAddress($recipient_email$recipient_name);
  77.       }
  78.  
  79.     if ($extra_headers != ""){
  80.         $mail->AddCustomHeader($extra_headers);
  81.     }
  82.    //send mail
  83.    if (!$mail->Send())
  84.    {
  85.         //echo "ERROR: mail not sent to ".$recipient_name." (".$recipient_email.") because of ".$mail->ErrorInfo."<br>";
  86.         return 0;
  87.    }
  88.  
  89.    // Clear all addresses
  90.    $mail->ClearAddresses();
  91.    return 1;
  92.  }
  93.  
  94. /**
  95.  * Sends an HTML email using the phpmailer class (and multipart/alternative to downgrade gracefully)
  96.  * Sender name and email can be specified, if not specified
  97.  * name and email of the platform admin are used
  98.  *
  99.  * @author Bert Vanderkimpen ICT&O UGent
  100.  * @author Yannick Warnier <yannick.warnier@dokeos.com>
  101.  *
  102.  * @param string               name of recipient
  103.  * @param string              email of recipient
  104.  * @param string            email subject
  105.  * @param string            email body
  106.  * @param string            sender name
  107.  * @param string            sender e-mail
  108.  * @param array                extra headers in form $headers = array($name => $value) to allow parsing
  109.  * @return                  returns true if mail was sent
  110.  * @see                     class.phpmailer.php
  111.  */
  112. function api_mail_html($recipient_name$recipient_email$subject$message$sender_name=""$sender_email=""$extra_headers=null{
  113.  
  114.    global $regexp;
  115.    global $platform_email;
  116.  
  117.    $mail new PHPMailer();
  118.    $mail->Mailer  $platform_email['SMTP_MAILER'];
  119.    $mail->Host    $platform_email['SMTP_HOST'];
  120.    $mail->Port    $platform_email['SMTP_PORT'];
  121.  
  122.    if($platform_email['SMTP_AUTH'])
  123.    {
  124.       $mail->SMTPAuth 1;
  125.       $mail->Username $platform_email['SMTP_USER'];
  126.       $mail->Password $platform_email['SMTP_PASS'];
  127.    }
  128.  
  129.    $mail->Priority 3// 5=low, 1=high
  130.    $mail->AddCustomHeader("Errors-To: ".$platform_email['SMTP_FROM_EMAIL']."");
  131.    $mail->IsHTML(0);
  132.    $mail->SMTPKeepAlive true;
  133.  
  134.  
  135.    // attachments
  136.    // $mail->AddAttachment($path);
  137.    // $mail->AddAttachment($path,$filename);
  138.  
  139.  
  140.    if ($sender_email!="")
  141.    {
  142.       $mail->From           $sender_email;
  143.       $mail->Sender       $sender_email;
  144.       //$mail->ConfirmReadingTo = $sender_email; //Disposition-Notification
  145.    }
  146.    else
  147.     {
  148.       $mail->From         $platform_email['SMTP_FROM_EMAIL'];
  149.       $mail->Sender     $platform_email['SMTP_FROM_EMAIL'];
  150.       //$mail->ConfirmReadingTo = $platform_email['SMTP_FROM_EMAIL']; //Disposition-Notification
  151.     }
  152.  
  153.  
  154.    if ($sender_name!="")
  155.    {
  156.       $mail->FromName $sender_name;
  157.    }
  158.    else
  159.    {
  160.       $mail->FromName $platform_email['SMTP_FROM_NAME'];
  161.    }
  162.       $mail->Subject $subject;
  163.       $mail->AltBody    strip_tags(str_replace('<br />',"\n",$message));
  164.       $mail->Body    '<html><head></head><body>'.$message.'</body></html>';
  165.       //only valid address
  166.       if(is_array($recipient_email))
  167.       {
  168.           $i 0;
  169.         foreach($recipient_email as $dest)
  170.         {
  171.           if(eregi$regexp$dest ))
  172.           {
  173.               $mail->AddAddress($dest($i>1?'':$recipient_name));
  174.           }
  175.           $i++;
  176.         }
  177.       }
  178.       else
  179.       {
  180.           if(eregi$regexp$recipient_email ))
  181.           {
  182.               $mail->AddAddress($recipient_email$recipient_name);
  183.           }
  184.       }
  185.  
  186.     if (is_array($extra_headers&& count($extra_headers)>0){
  187.         foreach($extra_headers as $key=>$value)
  188.         {
  189.             switch(strtolower($key)){
  190.                 case 'encoding':
  191.                 case 'content-transfer-encoding':
  192.                     $mail->Encoding $value;
  193.                     break;
  194.                 case 'charset':
  195.                     $mail->Charset $value;
  196.                     break;
  197.                 case 'contenttype':
  198.                 case 'content-type':
  199.                     $mail->ContentType $value;
  200.                     break;
  201.                 default:
  202.                     $mail->AddCustomHeader($key.':'.$value);
  203.                     break;
  204.             }
  205.         }
  206.     }
  207.    //send mail
  208.    if (!$mail->Send())
  209.    {
  210.         //echo "ERROR: mail not sent to ".$recipient_name." (".$recipient_email.") because of ".$mail->ErrorInfo."<br>";
  211.         return 0;
  212.    }
  213.  
  214.    // Clear all addresses
  215.    $mail->ClearAddresses();
  216.    return 1;
  217.  }
  218.  
  219. ?>

Documentation generated on Thu, 12 Jun 2008 14:03:50 -0500 by phpDocumentor 1.4.1