[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/modules/Emails/ -> sendmail.php (source)

   1  <?php
   2  ////////////////////////////////////////////////////
   3  // PHPMailer - PHP email class
   4  //
   5  // Class for sending email using either
   6  // sendmail, PHP mail(), or SMTP.  Methods are
   7  // based upon the standard AspEmail(tm) classes.
   8  //
   9  // Copyright (C) 2001 - 2003  Brent R. Matzelle
  10  //
  11  // License: LGPL, see LICENSE
  12  ////////////////////////////////////////////////////
  13  
  14  /**
  15   * PHPMailer - PHP email transport class
  16   * @package PHPMailer
  17   * @author Brent R. Matzelle
  18   * @copyright 2001 - 2003 Brent R. Matzelle
  19   */
  20  
  21  require_once ('modules/Emails/Emails.php');
  22  require_once ('include/logging.php');
  23  require ("modules/Emails/class.phpmailer.php");
  24  require_once ('include/database/PearDatabase.php');
  25  
  26  $local_log =& LoggerManager::getLogger('index');
  27  
  28  echo get_module_title("Emails", $mod_strings['LBL_MODULE_NAME'], true); 
  29  
  30  sendmail($_REQUEST['assigned_user_id'],$current_user->user_name,$_REQUEST['name'],$_REQUEST['description'],$mail_server,$mail_server_username,$mail_server_password);
  31  
  32  function sendmail($to,$from,$subject,$contents,$mail_server,$mail_server_username,$mail_server_password)
  33  {
  34      global $adb,$root_directory,$mod_strings, $log;
  35  
  36      $sql = $_REQUEST['query'];
  37      $result= $adb->query($sql);
  38      
  39      $noofrows = $adb->num_rows($result);
  40  
  41      $dbQuery = 'select vtiger_attachments.*, vtiger_activity.subject, vtiger_crmentity.description  from vtiger_activity inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_activity.activityid left join vtiger_seattachmentsrel on vtiger_seattachmentsrel.crmid = vtiger_activity.activityid left join vtiger_attachments on vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid where vtiger_crmentity.crmid = '.$adb->quote($_REQUEST['return_id']);
  42  
  43          $result1 = $adb->query($dbQuery) or die("Couldn't get file list");
  44      $temparray = $adb->fetch_array($result1);
  45  
  46      $notequery = 'select  vtiger_attachments.*, vtiger_notes.notesid, vtiger_notes.filename,vtiger_notes.notecontent  from vtiger_notes inner join vtiger_senotesrel on vtiger_senotesrel.notesid= vtiger_notes.notesid inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_senotesrel.crmid left join vtiger_seattachmentsrel  on vtiger_seattachmentsrel.crmid =vtiger_notes.notesid left join vtiger_attachments on vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid where vtiger_crmentity.crmid='.$adb->quote($_REQUEST['return_id']);
  47      $result2 = $adb->query($notequery) or die("Couldn't get file list");
  48  
  49      $mail = new PHPMailer();
  50      
  51          $mail->Subject =$adb->query_result($result1,0,"subject");
  52  
  53      $DESCRIPTION = $adb->query_result($result1,0,"description");
  54      $DESCRIPTION .= '<br><br>';
  55      $DESCRIPTION .= '<font color=darkgrey>'.nl2br($adb->query_result($adb->query("select * from vtiger_users where user_name=".$adb->quote($from)),0,"signature")).'</font>';
  56  
  57      $mail->IsHTML(true);
  58          $mail->Body    = nl2br($DESCRIPTION);
  59      $mail->AltBody = strip_tags(preg_replace(array("/<p>/i","/<br>/i","/<br \/>/i"),array("\n","\n","\n"),$DESCRIPTION));
  60      $initialfrom = $from;
  61      $mail->IsSMTP();
  62  
  63      if($mail_server=='')
  64      {
  65              $mailserverresult = $adb->query("select * from vtiger_systems where server_type = 'email'");
  66              $mail_server = $adb->query_result($mailserverresult,0,'server');
  67          $mail_server_username = $adb->query_result($mailserverresult,0,'server_username');
  68                  $mail_server_password = $adb->query_result($mailserverresult,0,'server_password');
  69                  $smtp_auth = $adb->query_result($mailserverresult,0,'smtp_auth');
  70          $_REQUEST['server']=$mail_server;
  71  
  72          $log->info("Mail Server Details => '".$mail_server."','".$mail_server_username."','".$mail_server_password."'");
  73      }
  74      $mail->Host = $mail_server;
  75      $mail->SMTPAuth = $smtp_auth;
  76      $mail->Username = $mail_server_username;
  77      $mail->Password = $mail_server_password;
  78      //$mail->From = $adb->query_result($adb->query("select * from vtiger_users where user_name='".$from."'"),0,"email1");
  79  
  80      $mail->From = $adb->query_result($adb->query("select * from vtiger_users where user_name=".$adb->quote($from)),0,"email1");
  81      $mail->FromName = $initialfrom;
  82      $mail->AddReplyTo($from);
  83      $mail->WordWrap = 50;
  84      $log->info("From name & id are set in mail object => '".$mail->FromName."<".$mail->From.">' ");
  85  
  86      //store this to the hard disk and give that url
  87      for($i=0;$i< $adb->num_rows($result1);$i++)
  88      {
  89          $fileContent = $adb->query_result($result1,$i,"attachmentcontents");
  90          $filename=$adb->query_result($result1,$i,"name");
  91          $filesize=$adb->query_result($result1,$i,"attachmentsize");
  92  
  93          if(!@$handle = fopen($root_directory."/test/upload/".$filename,"wb")){}
  94  
  95          if(!@fwrite($handle,base64_decode($fileContent),$filesize)){}
  96          if(!@fclose($handle)){}
  97  
  98          $mail->AddAttachment($root_directory."/test/upload/".$filename);//temparray['filename']) // add vtiger_attachments
  99          $log->info("File '".$filename."' is attached with the mail.");
 100      }
 101  
 102      for($i=0;$i< $adb->num_rows($result2);$i++)
 103      {
 104          $fileContent = $adb->query_result($result2,$i,"attachmentcontents");
 105          $filename=$adb->query_result($result2,$i,"name");
 106          $filesize=$adb->query_result($result2,$i,"attachmentsize");
 107  
 108          if(!@$handle = fopen($root_directory."/test/upload/".$filename,"wb")){}
 109  
 110          if(!@fwrite($handle,base64_decode($fileContent),$filesize)){}
 111          if(!@fclose($handle)){}
 112  
 113          $mail->AddAttachment($root_directory."/test/upload/".$filename);//temparray['filename']) // add vtiger_attachments
 114          $log->info("File '".$filename."' is attached with the mail.");
 115      }
 116  
 117      echo '<table>';
 118  
 119      $count = 1;
 120      for($i=0;$i< $noofrows;$i++)
 121      {
 122          $mail->ClearAddresses();
 123          if($_REQUEST['mailto'] == 'users')
 124          {
 125              $to=$adb->query_result($result,$i,"email1");
 126              if($to == '')
 127                  $to=$adb->query_result($result,$i,"email2");
 128              if($to == '')
 129                  $to=$adb->query_result($result,$i,"yahoo_id");
 130          }
 131          else
 132              $to=$adb->query_result($result,$i,"email");
 133  
 134          $mail->AddAddress($to);
 135          $log->info("To email address is added in the mail object => '".$to."'");
 136          $emailoptout = $adb->query_result($result,$i,"emailoptout");
 137          if($emailoptout == 1 && $to != '')
 138          {
 139              $mail->ClearAddresses();
 140              $mail->AddAddress("");
 141              $emailoptout_error = true;
 142              $log->info("Email opt out (contact) value is set. So To email id address cleared(empty).");
 143          }
 144  
 145          $j=$i+1;
 146  
 147  
 148          if($mail->Send())
 149          {
 150              $flag = true;
 151              if($flag && $count == 1 && $noofrows >= 1)
 152              {
 153                  $count = 0;
 154                  if($_REQUEST['mailto'] == 'users')
 155                      echo '<tr><b><h3>'.$mod_strings['MESSAGE_MAIL_HAS_SENT_TO_USERS'].' </h3></b></tr>';
 156                  else
 157                      echo '<tr><b><h3>'.$mod_strings['MESSAGE_MAIL_HAS_SENT_TO_CONTACTS'].' </h3></b></tr>';
 158              }
 159              echo '<center><tr align="left"><b><h3>'.$j.' . '.$to.'</h3></b></tr></center>';
 160              $log->info("Mail has been sent from vtiger system. Status => '".$mail->ErrorInfo."'");
 161          }
 162          else
 163          {
 164              $log->info("Error block : Mail sending process failed. Status => '".$mail->ErrorInfo."'");
 165              $message = substr($mail->ErrorInfo,0,49);
 166              $flag = false;
 167              if($message=='Language string failed to load: connect_host')
 168              {
 169                  if($i == 0)
 170                      echo "<br><b><h3>".$mod_strings['MESSAGE_CHECK_MAIL_SERVER_NAME']."</b></h3>";
 171              }
 172              elseif( $count == 1 && $noofrows >= 1)
 173              {
 174                  $count = 0;
 175                  if($_REQUEST['mailto'] == 'users')
 176                      echo '<tr><b><h3>'.$mod_strings['MESSAGE_MAIL_HAS_SENT_TO_USERS'].' </h3></b></tr>';
 177                  else
 178                      echo '<tr><b><h3>'.$mod_strings['MESSAGE_MAIL_HAS_SENT_TO_CONTACTS'].' </h3></b></tr>';
 179              }
 180              if($message=='Language string failed to load: recipients_failed')
 181              {
 182                  if($emailoptout_error == true)
 183                  {
 184                      $ERROR_MESSAGE = $mod_strings['MESSAGE_CONTACT_NOT_WANT_MAIL'];
 185                      $flag = true;
 186                  }
 187                  else
 188                      $ERROR_MESSAGE = $mod_strings['MESSAGE_MAIL_ID_IS_INCORRECT'];
 189  
 190                  echo '<center><tr align="left"><font color="purple"<b><h3>'.$j.' . '.$ERROR_MESSAGE.' </h3></font></b></tr></center>';
 191              }
 192          }
 193      }
 194  
 195      if($i==0)
 196          echo '<br><td align="left"><font color="red"><b><center><h3>'.$mod_strings['MESSAGE_ADD_USER_OR_CONTACT'].'</h3></b></font>';
 197      if($i>1 && $flag)
 198          echo "<br><br><B><center><h3>".$mod_strings['MESSAGE_MAIL_SENT_SUCCESSFULLY']." </h3></B>";
 199      echo '</table>';
 200  
 201  }
 202  
 203  ?>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7