Location: PHPKode > projects > Laikwan WMC > wmc_20070325/gmlite/loadSend.php
<?
   require_once("config.php");
   
   $from = isset($_REQUEST["from"])?$_REQUEST["from"]:"";
   $to = isset($_REQUEST["to"])?$_REQUEST["to"]:"";
   $cc = isset($_REQUEST["cc"])?$_REQUEST["cc"]:"";
   $bcc = isset($_REQUEST["bcc"])?$_REQUEST["bcc"]:"";
   $subj = isset($_REQUEST["subj"])?$_REQUEST["subj"]:"";
   $body = isset($_REQUEST["body"])?$_REQUEST["body"]:"";

   //$back = isset($_REQUEST["back"])?$_REQUEST["back"]:"";
   
   $th = isset($_REQUEST["th"])?$_REQUEST["th"]:"";
   $mg = isset($_REQUEST["mg"])?$_REQUEST["mg"]:"";
   $df = isset($_REQUEST["df"])?$_REQUEST["df"]:0;
   $orig_df = isset($_REQUEST["orig_df"])?$_REQUEST["orig_df"]:"";
   $draft_attach = isset($_REQUEST["draft_attach"])?$_REQUEST["draft_attach"]:"";

   // address book related
   $list = isset($_REQUEST["list"])?$_REQUEST["list"]:array();
   $list_to = isset($_REQUEST["list_to"])?$_REQUEST["list_to"]:"";

   // action to be done
   // $discard = isset($_REQUEST["discard"])?$_REQUEST["discard"]:"";
   $send = isset($_REQUEST["send"])?$_REQUEST["send"]:"";


	
   $err = "";
   $status = false;
   
   $gm = new GMailer();
   if (!$gm->created)
      die("Failed to create GMailer.");      
   quick_init($gm);
   
   if ($gm->connect()) {   
         
         if (strlen($to)>0 ) { // && $back

			// attachments to get - comma separated list
			$attachNames = isset($_REQUEST["attachNames"])?$_REQUEST["attachNames"]:"";
			$attachArr = split(",", $attachNames);
/*$body .= "\n\n\n";
$body .= 'attachNames: ' . $attachNames . "\n";
*/
			// attachment uploaded
			$fname = array();
			foreach ($attachArr as $val) {
				$filename = isset($_FILES['attach'.$val]['name'])? $_FILES['attach'.$val]['name'] : 0;
				$filesize = isset($_FILES['attach'.$val]['size'])? $_FILES['attach'.$val]['size'] : -1;
				$filetype = isset($_FILES['attach'.$val]['type'])? $_FILES['attach'.$val]['type'] : 0;
				$filetmp = isset($_FILES['attach'.$val]['tmp_name'])? $_FILES['attach'.$val]['tmp_name'] : 0;
/*$body .= "attach: ".'attach'.$val . "\n";
$body .= "filename: ".$filename . "\n";
$body .= "filesize: ".$filesize . "\n";
*/				if ($filename && $filetmp && $filesize > 0 && $filesize < 5000000 && C_ATTACHMENT) {
					if (move_uploaded_file($filetmp, realpath("./tmp")."/".$filename)) {
						$fname[] = "./tmp/".$filename;
					}
				}
			}
			if(count($fname) == 0){
				$fname = 0;
			}


            if ($send)
               $status = $gm->send($to, $subj, $body, $cc, $bcc, $mg, $th, $fname, false, $orig_df, false, $from);	// send
            else 
               $status = $gm->send($to, $subj, $body, $cc, $bcc, $mg, $th, $fname, true, $orig_df, false, $from);   // save draft only

            if(!$status)
				  $err = $gm->lastActionStatus();

            if ($fname)
               unlink($fname[0]);

      }      
      
   } else {
      $err = "You have to login first.";
   }

	header("Content-type: text/html; charset=utf-8");  // must use text/xml for ajax/xmlhttp to work :(
	header("Pragma: no-cache");  // stop caching	

	echo "<html>";
	echo "<script>";
	echo "top.COMPOSE.composeTargetIframeLoaded('" . $status . "','" . $err . "','" . $send . "');";
	echo "</script>";
	echo "</html>";

?>
Return current item: Laikwan WMC