Guest User

send_email

a guest
Dec 30th, 2014
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1. function send_email($address,$subject,$body,$noheaders=0,$custom_header=0) {
  2.  
  3.     include_once("class.phpmailer.php");
  4.     include_once("class.smtp.php");
  5.  
  6.     global $MAIL_SETTINGS;
  7.  
  8.     $myheader = file_get_contents("includes/email_header.php");
  9.     $myfooter = file_get_contents("includes/email_footer.php");
  10.  
  11.     if ($MAIL_SETTINGS["mail_enabled"] == 1) {
  12.  
  13.         $from_email_address = $GLOBALS["vision_system_address"];
  14.         if ($from_email_address == "") { $from_email_address = "[email protected]"; }
  15.  
  16.         // generate the email
  17.         $curdate = gmdate("D M j, g:ia");
  18.  
  19.         $myemail = "";
  20.         $myemail .= $myheader;
  21.  
  22.         if (!$noheaders) {
  23.             $myemail .= "<h1 style=\"font-family: Arial; font-size: 16pt; color: #2F4D85; letter-spacing: -1px; margin-bottom: 13px; font-weight: normal;\">$subject</h1>\n";
  24.         }
  25.  
  26.         $myemail .= $body;
  27.         $myemail .= $myfooter;
  28.  
  29.         // send the email
  30.         $mail = new PHPMailer();
  31.         $me = current_user();
  32.  
  33.         $mail_name = "";
  34.         $mail_address = "";
  35.  
  36.         if (intval($me) != 0) {
  37.  
  38.             $myquery = sql_query("SELECT userid, forename, surname, email_primary FROM nucleus_users WHERE userid='$me'");
  39.  
  40.             if (sql_num_rows($myquery)) {
  41.                 $myrow = sql_fetch_row($myquery);
  42.                 $mail_name = trim($myrow[1]." ".$myrow[2]);
  43.                 $mail_address = $myrow[3];
  44.             }
  45.  
  46.         }
  47.  
  48.         if($custom_header != 0){
  49.             $mail->AddCustomHeader = $custom_header;
  50.         }
  51.  
  52.         if (($mail_name != "") and ($mail_address != "")) {
  53.  
  54.             $mail->From = $mail_address;
  55.             $mail->FromName = $mail_name;
  56.  
  57.             $mail->UseOriginalSender = true;
  58.             $mail->OriginalSender = $from_email_address;
  59.             $mail->OriginalSenderName = $GLOBALS["vision_product_name"];
  60.  
  61.         } else {
  62.             $mail->From = $from_email_address;
  63.             $mail->FromName = $GLOBALS["vision_product_name"];
  64.         }
  65.  
  66.         $mail->AddAddress($address);
  67.         $mail->IsHTML(true);
  68.         $mail->IsSMTP(true);
  69.  
  70.         $mail->Host = $MAIL_SETTINGS["host"];
  71.  
  72.         if ($MAIL_SETTINGS["auth"]) {
  73.             $mail->Username = $MAIL_SETTINGS["username"];
  74.             $mail->Password = $MAIL_SETTINGS["password"];
  75.         }
  76.  
  77.         // embed images
  78.  
  79.         if (is_file("images/vision_small.png")) {
  80.             $mail->AddEmbeddedImage("images/vision_small.png","vision_small","vision_small.png","base64","image/png");
  81.         } elseif (is_file("../httpdocs/images/vision_small.png")) {
  82.             $mail->AddEmbeddedImage("../httpdocs/images/vision_small.png","vision_small","vision_small.png","base64","image/png");
  83.         }
  84.  
  85.         // create and send
  86.  
  87.         if (!$noheaders) {
  88.             $subject = "$subject";
  89.         }
  90.  
  91.         $mail->Subject = "$subject";
  92.         $mail->Body = $myemail;
  93.         $mail->AltBody = strip_tags($body);
  94.         $mail->Send();
  95.  
  96.     }
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment