/** * this function is a wrapper to the php mail() function so that we can change settings globally * for more info on format="flowed" see: http://www.joeclark.org/ffaq.html * for deatiled info on MIME (RFC 1521) email see: http://www.freesoft.org/CIE/RFC/1521/index.htm */ function pgvMail($to, $from, $subject, $message) { global $PGV_SMTP_ACTIVE, $PGV_SMTP_HOST, $PGV_SMTP_HELO, $PGV_SMTP_FROM_NAME, $PGV_SMTP_PORT, $PGV_SMTP_AUTH, $PGV_SMTP_AUTH_USER, $PGV_SMTP_AUTH_PASS, $PGV_SMTP_SSL; global $pgv_lang, $CHARACTER_SET, $LANGUAGE, $PGV_STORE_MESSAGES, $TEXT_DIRECTION; $mailFormat = "plain"; //$mailFormat = "html"; //$mailFormat = "multipart"; $mailFormatText = "text/plain"; $boundary = "PGV-123454321-PGV"; //unique identifier for multipart $boundary2 = "PGV-123454321-PGV2"; if ($TEXT_DIRECTION == "rtl") { // needed for rtl but we can change this to a global config $mailFormat = "html"; } if ($mailFormat == "html") { $mailFormatText = "text/html"; } else { if ($mailFormat == "multipart") { $mailFormatText = "multipart/related; \n\tboundary=\"{$boundary}\""; //for double display use:multipart/mixed } else { $mailFormatText = "text/plain"; } } $extraHeaders = "From: {$from}\nContent-type: {$mailFormatText};"; if ($mailFormat != "multipart") { $extraHeaders .= "\tcharset=\"{$CHARACTER_SET}\";\tformat=\"flowed\"\nContent-Transfer-Encoding: 8bit"; } if ($mailFormat == "html" || $mailFormat == "multipart") { $extraHeaders .= "\nMime-Version: 1.0"; } $extraHeaders .= "\n"; if ($mailFormat == "html") { //wrap message in html $htmlMessage = ""; $htmlMessage .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; $htmlMessage .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">"; $htmlMessage .= "<head>"; $htmlMessage .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"; $htmlMessage .= "</head>"; $htmlMessage .= "<body dir=\"{$TEXT_DIRECTION}\"><pre>"; $htmlMessage .= $message; //add message $htmlMessage .= "</pre></body>"; $htmlMessage .= "</html>"; $message = $htmlMessage; } else { if ($mailFormat == "multipart") { //wrap message in html $htmlMessage = "--{$boundary}\n"; $htmlMessage .= "Content-Type: multipart/alternative; \n\tboundary=--{$boundary2}\n\n"; $htmlMessage = "--{$boundary2}\n"; $htmlMessage .= "Content-Type: text/plain; \n\tcharset=\"{$CHARACTER_SET}\";\n\tformat=\"flowed\"\nContent-Transfer-Encoding: 8bit\n\n"; $htmlMessage .= $message; $htmlMessage .= "\n\n--{$boundary2}\n"; $htmlMessage .= "Content-Type: text/html; \n\tcharset=\"{$CHARACTER_SET}\";\n\tformat=\"flowed\"\nContent-Transfer-Encoding: 8bit\n\n"; $htmlMessage .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; $htmlMessage .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">"; $htmlMessage .= "<head>"; $htmlMessage .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"; $htmlMessage .= "</head>"; $htmlMessage .= "<body dir=\"{$TEXT_DIRECTION}\"><pre>"; $htmlMessage .= $message; //add message $htmlMessage .= "</pre>"; $htmlMessage .= "<img src=\"cid:pgvlogo@pgvserver\" alt=\"\" style=\"border: 0px; display: block; margin-left: auto; margin-right: auto;\" />"; $htmlMessage .= "</body>"; $htmlMessage .= "</html>"; $htmlMessage .= "\n--{$boundary2}--\n"; $htmlMessage .= "\n--{$boundary}\n"; $htmlMessage .= getPgvMailLogo(); $htmlMessage .= "\n\n\n\n--{$boundary}--"; $message = $htmlMessage; } } // if SMTP mail is set active AND we have SMTP settings available, use the PHPMailer classes if ($PGV_SMTP_ACTIVE && ($PGV_SMTP_HOST && $PGV_SMTP_PORT)) { require_once 'includes/class.phpmailer.php'; $mail_object = new PHPMailer(); $mail_object->IsSMTP(); $mail_object->SetLanguage('en', 'languages/'); if ($PGV_SMTP_AUTH && ($PGV_SMTP_AUTH_USER && $PGV_SMTP_AUTH_PASS)) { $mail_object->SMTPAuth = $PGV_SMTP_AUTH; $mail_object->Username = $PGV_SMTP_AUTH_USER; $mail_object->Password = $PGV_SMTP_AUTH_PASS; } if ($PGV_SMTP_SSL == 'ssl') { $mail_object->SMTPSecure = 'ssl'; } else { if ($PGV_SMTP_SSL == 'tls') { $mail_object->SMTPSecure = 'tls'; } } $mail_object->Host = $PGV_SMTP_HOST; $mail_object->Port = $PGV_SMTP_PORT; $mail_object->Hostname = $PGV_SMTP_HELO; $mail_object->From = $from; if (!empty($PGV_SMTP_FROM_NAME) && $from != $PGV_SMTP_AUTH_USER) { $mail_object->FromName = $PGV_SMTP_FROM_NAME; $mail_object->AddAddress($to); } else { $mail_object->FromName = $mail_object->AddAddress($to); } $mail_object->Subject = hex4email($subject, $CHARACTER_SET); $mail_object->ContentType = $mailFormatText; if ($mailFormat != "multipart") { $mail_object->ContentType = $mailFormatText . '; format="flowed"'; $mail_object->CharSet = $CHARACTER_SET; $mail_object->Encoding = '8bit'; } if ($mailFormat == "html" || $mailFormat == "multipart") { $mail_object->AddCustomHeader('Mime-Version: 1.0'); $mail_object->IsHTML(true); } $mail_object->Body = $message; // attempt to send mail if (!$mail_object->Send()) { echo 'Message was not sent.<br />'; echo 'Mailer error: ' . $mail_object->ErrorInfo . '<br />'; return; } else { // SMTP OK return; } } else { // use original PGV mail sending function mail($to, hex4email($subject, $CHARACTER_SET), $message, $extraHeaders); } }
function addMessage($message) { global $TBLPREFIX, $CONTACT_METHOD, $pgv_lang, $CHARACTER_SET, $LANGUAGE, $PGV_STORE_MESSAGES, $SERVER_URL, $PGV_SIMPLE_MAIL, $WEBMASTER_EMAIL; global $TEXT_DIRECTION, $TEXT_DIRECTION_array, $DATE_FORMAT, $DATE_FORMAT_array, $TIME_FORMAT, $TIME_FORMAT_array, $WEEK_START, $WEEK_START_array; global $PHPGEDVIEW_EMAIL; //-- do not allow users to send a message to themselves if ($message["from"] == $message["to"]) { return false; } require_once 'includes/functions/functions_mail.php'; if (!get_user_id($message["to"])) { //-- the to user must be a valid user in the system before it will send any mails return false; } // Switch to the "from" user's language $oldLanguage = $LANGUAGE; $from_lang = get_user_setting($message["from"], 'language'); if ($from_lang && $LANGUAGE != $from_lang) { loadLanguage($from_lang); } //-- setup the message body for the "from" user $email2 = stripslashes($message["body"]); if (isset($message["from_name"])) { $email2 = $pgv_lang["message_from_name"] . " " . $message["from_name"] . "\r\n" . $pgv_lang["message_from"] . " " . $message["from_email"] . "\r\n\r\n" . $email2; } if (!empty($message["url"])) { $email2 .= "\r\n\r\n--------------------------------------\r\n\r\n" . $pgv_lang["viewing_url"] . "\r\n" . $SERVER_URL . $message["url"] . "\r\n"; } $email2 .= "\r\n=--------------------------------------=\r\nIP ADDRESS: " . $_SERVER['REMOTE_ADDR'] . "\r\n"; $email2 .= "DNS LOOKUP: " . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "\r\n"; $email2 .= "LANGUAGE: {$LANGUAGE}\r\n"; $subject2 = "[" . $pgv_lang["phpgedview_message"] . ($TEXT_DIRECTION == "ltr" ? "] " : " [") . stripslashes($message["subject"]); $from = ""; if (!get_user_id($message["from"])) { $from = $message["from"]; $email2 = $pgv_lang["message_email3"] . "\r\n\r\n" . stripslashes($email2); $fromFullName = $message["from"]; } else { $fromFullName = getUserFullName($message['from']); if (!$PGV_SIMPLE_MAIL) { $from = hex4email(stripslashes($fromFullName), $CHARACTER_SET) . " <" . get_user_setting($message["from"], 'email') . ">"; } else { $from = get_user_setting($message["from"], 'email'); } $email2 = $pgv_lang["message_email2"] . "\r\n\r\n" . stripslashes($email2); } if ($message["method"] != "messaging") { $subject1 = "[" . $pgv_lang["phpgedview_message"] . ($TEXT_DIRECTION == "ltr" ? "] " : " [") . stripslashes($message["subject"]); if (!get_user_id($message["from"])) { $email1 = $pgv_lang["message_email1"]; if (!empty($message["from_name"])) { $email1 .= $message["from_name"] . "\r\n\r\n" . stripslashes($message["body"]); } else { $email1 .= $from . "\r\n\r\n" . stripslashes($message["body"]); } } else { $email1 = $pgv_lang["message_email1"]; $email1 .= stripslashes($fromFullName) . "\r\n\r\n" . stripslashes($message["body"]); } if (!isset($message["no_from"])) { if (stristr($from, $PHPGEDVIEW_EMAIL)) { $from = get_user_setting($WEBMASTER_EMAIL, 'email'); } if (!get_user_id($message["from"])) { $header2 = $PHPGEDVIEW_EMAIL; } else { if (isset($to)) { $header2 = $to; } } if (!empty($header2)) { pgvMail($from, $header2, $subject2, $email2); } } } //-- Load the "to" users language $to_lang = get_user_setting($message["to"], 'language'); if ($to_lang && $LANGUAGE != $to_lang) { loadLanguage($to_lang); } if (isset($message["from_name"])) { $message["body"] = $pgv_lang["message_from_name"] . " " . $message["from_name"] . "\r\n" . $pgv_lang["message_from"] . " " . $message["from_email"] . "\r\n\r\n" . $message["body"]; } //-- [ phpgedview-Feature Requests-1588353 ] Supress admin IP address in Outgoing PGV Email if (!userIsAdmin(get_user_id($message["from"]))) { if (!empty($message["url"])) { $message["body"] .= "\r\n\r\n--------------------------------------\r\n\r\n" . $pgv_lang["viewing_url"] . "\r\n" . $SERVER_URL . $message["url"] . "\r\n"; } $message["body"] .= "\r\n=--------------------------------------=\r\nIP ADDRESS: " . $_SERVER['REMOTE_ADDR'] . "\r\n"; $message["body"] .= "DNS LOOKUP: " . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "\r\n"; $message["body"] .= "LANGUAGE: {$LANGUAGE}\r\n"; } if (empty($message["created"])) { $message["created"] = gmdate("D, d M Y H:i:s T"); } if ($PGV_STORE_MESSAGES && ($message["method"] != "messaging3" && $message["method"] != "mailto" && $message["method"] != "none")) { PGV_DB::prepare("INSERT INTO {$TBLPREFIX}messages (m_id, m_from, m_to, m_subject, m_body, m_created) VALUES (?, ? ,? ,? ,? ,?)")->execute(array(get_next_id("messages", "m_id"), $message["from"], $message["to"], $message["subject"], $message["body"], $message["created"])); } if ($message["method"] != "messaging") { $subject1 = "[" . $pgv_lang["phpgedview_message"] . ($TEXT_DIRECTION == "ltr" ? "] " : " [") . stripslashes($message["subject"]); if (!get_user_id($message["from"])) { $email1 = $pgv_lang["message_email1"]; if (!empty($message["from_name"])) { $email1 .= $message["from_name"] . "\r\n\r\n" . stripslashes($message["body"]); } else { $email1 .= $from . "\r\n\r\n" . stripslashes($message["body"]); } } else { $email1 = $pgv_lang["message_email1"]; $email1 .= stripslashes($fromFullName) . "\r\n\r\n" . stripslashes($message["body"]); } if (!get_user_id($message["to"])) { //-- the to user must be a valid user in the system before it will send any mails return false; } else { $toFullName = getUserFullName($message['to']); if (!$PGV_SIMPLE_MAIL) { $to = hex4email(stripslashes($toFullName), $CHARACTER_SET) . " <" . get_user_setting($message["to"], 'email') . ">"; } else { $to = get_user_setting($message["to"], 'email'); } } if (get_user_setting($message["to"], 'email')) { pgvMail($to, $from, $subject1, $email1); } } if ($LANGUAGE != $oldLanguage) { loadLanguage($oldLanguage); } // restore language settings if needed return true; }