1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

More updates ... added Date and Content-type/encoding output for the emails, updated all email templates

git-svn-id: file:///svn/phpbb/branches/phpBB-2_0_0@2587 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen
2002-05-17 13:14:05 +00:00
parent 999480b9fd
commit 4b48ebcb4c
382 changed files with 2078 additions and 1618 deletions

View File

@@ -38,8 +38,8 @@ class emailer
$this->use_smtp = $use_smtp;
$this->tpl_file = NULL;
$this->address = NULL;
$this->msg = "";
$this->mimeOut = "";
$this->msg = '';
$this->mimeOut = '';
}
//
@@ -47,11 +47,11 @@ class emailer
//
function reset()
{
$this->tpl_file = "";
$this->address = "";
$this->msg = "";
$this->memOut = "";
$this->vars = "";
$this->tpl_file = '';
$this->address = '';
$this->msg = '';
$this->memOut = '';
$this->vars = '';
}
//
@@ -59,13 +59,8 @@ class emailer
//
function email_address($address)
{
$success = true;
$this->address = '';
$this->address .= $address;
return $success;
}
//
@@ -84,30 +79,27 @@ class emailer
$this->extra_headers = $headers;
}
function use_template($template_file, $template_lang = "")
function use_template($template_file, $template_lang = '')
{
global $board_config, $phpbb_root_path;
if( $template_lang == "" )
if ( $template_lang == '' )
{
$template_lang = $board_config['default_lang'];
}
$template_file = $phpbb_root_path . "language/lang_" . $template_lang . "/email/" . $template_file . ".tpl";
if( !file_exists($template_file) )
$this->tpl_file = $phpbb_root_path . 'language/lang_' . $template_lang . '/email/' . $template_file . '.tpl';
if ( !file_exists($this->tpl_file) )
{
message_die(GENERAL_ERROR, "Couldn't find template file: $template_file", "", __LINE__, __FILE__);
}
else
{
$this->tpl_file = $template_file;
if( !$this->load_msg() )
{
message_die(GENERAL_ERROR, "Couldn't load template file: $template_file", "", __LINE__, __FILE__);
}
message_die(GENERAL_ERROR, 'Could not find email template file ' . $template_file, '', __LINE__, __FILE__);
}
return TRUE;
if ( !$this->load_msg() )
{
message_die(GENERAL_ERROR, 'Could not load email template file ' . $template_file, '', __LINE__, __FILE__);
}
return true;
}
//
@@ -115,35 +107,25 @@ class emailer
//
function load_msg()
{
if ($this->tpl_file == NULL)
if ( $this->tpl_file == NULL )
{
message_die(GENERAL_ERROR, "No template file set", "", __LINE__, __FILE__);
message_die(GENERAL_ERROR, 'No template file set', '', __LINE__, __FILE__);
}
else
if ( !($fd = fopen($this->tpl_file, 'r')) )
{
if(!($fd = fopen($this->tpl_file, 'r')))
{
message_die(GENERAL_ERROR, "fopen failed opening template file", "", __LINE__, __FILE__);
}
else
{
$this->msg .= fread($fd, filesize($this->tpl_file));
fclose($fd);
}
message_die(GENERAL_ERROR, 'Failed opening template file', '', __LINE__, __FILE__);
}
return TRUE;
$this->msg .= fread($fd, filesize($this->tpl_file));
fclose($fd);
return true;
}
function assign_vars($vars)
{
if(empty($this->vars))
{
$this->vars = $vars;
}
else
{
$this->vars .= $vars;
}
$this->vars = ( empty($this->vars) ) ? $vars : $this->vars . $vars;
}
function parse_email()
@@ -165,12 +147,13 @@ class emailer
// do this here because the subject may contain a variable
//
$match = array();
preg_match("/^(Subject:(.*?)[\r\n]+?)?(.*?)$/is", $this->msg, $match);
preg_match("/^(Subject:(.*?)[\r\n]+?)?(Charset:(.*?)[\r\n]+?)?(.*?)$/is", $this->msg, $match);
$this->msg = ( isset($match[3]) ) ? trim($match[3]) : '';
$this->msg = ( isset($match[5]) ) ? trim($match[5]) : '';
$this->subject = ( $this->subject != '' ) ? $this->subject : trim($match[2]);
$this->encoding = ( trim($match[4]) != '' ) ? trim($match[4]) : 'iso-8859-1';
return TRUE;
return true;
}
//
@@ -180,45 +163,53 @@ class emailer
{
global $phpEx, $phpbb_root_path;
if ($this->address == NULL)
if ( $this->address == NULL )
{
message_die(GENERAL_ERROR, "No email address set", "", __LINE__, __FILE__);
message_die(GENERAL_ERROR, 'No email address set', '', __LINE__, __FILE__);
}
if ( !$this->parse_email() )
{
return false;
}
//
// Add date and encoding type
//
$universal_extra = "MIME-Version: 1.0\r\nContent-type: text/plain; charset=" . $this->encoding . "\r\nContent-transfer-encoding: 8bit\r\nDate: " . gmdate('D, d M Y H:i:s', time()) . " UT\r\n";
$this->extra_headers = $universal_extra . $this->extra_headers;
if ( $this->use_smtp )
{
if ( !defined('SMTP_INCLUDED') )
{
include($phpbb_root_path . 'includes/smtp.' . $phpEx);
}
$result = smtpmail($this->address, $this->subject, $this->msg, $this->extra_headers);
}
else
{
if(!$this->parse_email())
{
return FALSE;
}
if($this->use_smtp)
{
if(!defined('SMTP_INCLUDED'))
{
include($phpbb_root_path . "includes/smtp.".$phpEx);
}
if(!smtpmail($this->address, $this->subject, $this->msg, $this->extra_headers))
{
message_die(GENERAL_ERROR, "Sending via SMTP failed", "", __LINE__, __FILE__);
}
}
else
{
@mail($this->address, $this->subject, $this->msg, $this->extra_headers);
}
$result = @mail($this->address, $this->subject, $this->msg, $this->extra_headers);
}
return TRUE;
if ( !$result )
{
message_die(GENERAL_ERROR, 'Failed sending email', '', __LINE__, __FILE__);
}
return true;
}
//
// Attach files via MIME.
// Attach files via MIME.
//
function attachFile($filename, $mimetype="application/octet-stream", $szFromAddress, $szFilenameToDisplay)
function attachFile($filename, $mimetype = "application/octet-stream", $szFromAddress, $szFilenameToDisplay)
{
$mime_boundary = "--==================_846811060==_";
$this->mailMsg = "--".$mime_boundary."\nContent-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n\n".$this->mailMsg;
$this->mailMsg = '--' . $mime_boundary . "\nContent-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n\n" . $this->mailMsg;
if ($mime_filename)
{
@@ -234,11 +225,11 @@ class emailer
$this->mimeOut .= "Content-Transfer-Encoding: quoted-printable\n";
$this->mimeOut .= "Content-Disposition: attachment;\n\tfilename=\"$szFilenameToDisplay\"\n\n";
if ($mimetype == "message/rfc822")
if ( $mimetype == "message/rfc822" )
{
$this->mimeOut .= "From: ".$szFromAddress."\n";
$this->mimeOut .= "To: ".$this->emailAddress."\n";
$this->mimeOut .= "Date: ".date("D, d M Y G:i:s ").$this->getTimeZoneInEmailFormat()."\n";
$this->mimeOut .= "Date: ".date("D, d M Y H:i:s") . " UT\n";
$this->mimeOut .= "Reply-To:".$szFromAddress."\n";
$this->mimeOut .= "Subject: ".$this->mailSubject."\n";
$this->mimeOut .= "X-Mailer: PHP/".phpversion()."\n";

View File

@@ -55,7 +55,7 @@ function make_forum_select($box_name, $ignore_forum = false)
//
// Synchronise functions for forums/topics
//
function sync($type, $id)
function sync($type, $id = false)
{
global $db;

View File

@@ -267,7 +267,7 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_
{
$topic_vote = ( !empty($poll_title) && count($poll_options) >= 2 ) ? 1 : 0;
$sql = ( $mode != "editpost" ) ? "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote) VALUES ('$post_subject', " . $userdata['user_id'] . ", $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_vote)" : "UPDATE " . TOPICS_TABLE . " SET topic_title = '$post_subject', topic_type = $topic_type, topic_vote = $topic_vote WHERE topic_id = $topic_id";
if ( !($result = $db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
@@ -280,7 +280,7 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_
$edited_sql = ( $mode == 'editpost' && !$post_data['last_post'] && $post_data['poster_post'] ) ? ", post_edit_time = $current_time, post_edit_count = post_edit_count + 1 " : "";
$sql = ( $mode != "editpost" ) ? "INSERT INTO " . POSTS_TABLE . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip, enable_bbcode, enable_html, enable_smilies, enable_sig) VALUES ($topic_id, $forum_id, " . $userdata['user_id'] . ", '$post_username', $current_time, '$user_ip', $bbcode_on, $html_on, $smilies_on, $attach_sig)" : "UPDATE " . POSTS_TABLE . " SET enable_bbcode = $bbcode_on, enable_html = $html_on, enable_smilies = $smilies_on, enable_sig = $attach_sig" . $edited_sql . " WHERE post_id = $post_id";
if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
@@ -291,7 +291,7 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_
}
$sql = ( $mode != 'editpost' ) ? "INSERT INTO " . POSTS_TEXT_TABLE . " (post_id, post_subject, bbcode_uid, post_text) VALUES ($post_id, '$post_subject', '$bbcode_uid', '$post_message')" : "UPDATE " . POSTS_TEXT_TABLE . " SET post_text = '$post_message', bbcode_uid = '$bbcode_uid', post_subject = '$post_subject' WHERE post_id = $post_id";
if ( !($result = $db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
@@ -304,7 +304,7 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_
if ( ( $mode == 'newtopic' || $mode == 'editpost' ) && !empty($poll_title) && count($poll_options) >= 2 )
{
$sql = ( !$post_data['has_poll'] ) ? "INSERT INTO " . VOTE_DESC_TABLE . " (topic_id, vote_text, vote_start, vote_length) VALUES ($topic_id, '$poll_title', $current_time, " . ( $poll_length * 86400 ) . ")" : "UPDATE " . VOTE_DESC_TABLE . " SET vote_text = '$poll_title', vote_length = " . ( $poll_length * 86400 ) . " WHERE topic_id = $topic_id";
if ( !($result = $db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
@@ -348,7 +348,7 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_
$poll_result = ( $mode == "editpost" && isset($old_poll_result[$option_id]) ) ? $old_poll_result[$option_id] : 0;
$sql = ( $mode != "editpost" || !isset($old_poll_result[$option_id]) ) ? "INSERT INTO " . VOTE_RESULTS_TABLE . " (vote_id, vote_option_id, vote_option_text, vote_result) VALUES ($poll_id, $poll_option_id, '$option_text', $poll_result)" : "UPDATE " . VOTE_RESULTS_TABLE . " SET vote_option_text = '$option_text', vote_result = $poll_result WHERE vote_option_id = $option_id AND vote_id = $poll_id";
if ( !($result = $db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
@@ -359,8 +359,9 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_
if ( $delete_option_sql != '' )
{
$sql = "DELETE FROM " . VOTE_RESULTS_TABLE . "
WHERE vote_option_id IN ($delete_option_sql)";
if ( !($result = $db->sql_query($sql)) )
WHERE vote_option_id IN ($delete_option_sql)
AND vote_id = $poll_id";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error deleting pruned poll options', '', __LINE__, __FILE__, $sql);
}
@@ -395,12 +396,12 @@ function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_i
else
{
$topic_update_sql .= "topic_replies = topic_replies - 1";
$topic_update_sql .= 'topic_replies = topic_replies - 1';
$sql = "SELECT MAX(post_id) AS last_post_id
FROM " . POSTS_TABLE . "
WHERE topic_id = $topic_id";
if ( !($db->sql_query($sql)) )
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
@@ -416,7 +417,7 @@ function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_i
$sql = "SELECT MAX(post_id) AS last_post_id
FROM " . POSTS_TABLE . "
WHERE forum_id = $forum_id";
if ( !($db->sql_query($sql)) )
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
@@ -432,7 +433,7 @@ function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_i
$sql = "SELECT MIN(post_id) AS first_post_id
FROM " . POSTS_TABLE . "
WHERE topic_id = $topic_id";
if ( !($db->sql_query($sql)) )
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
@@ -460,7 +461,7 @@ function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_i
$sql = "UPDATE " . FORUMS_TABLE . " SET
$forum_update_sql
WHERE forum_id = $forum_id";
if ( !($result = $db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
@@ -471,7 +472,7 @@ function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_i
$topic_update_sql
WHERE topic_id = $topic_id
OR topic_moved_id = $topic_id";
if ( !($result = $db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
@@ -482,7 +483,7 @@ function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_i
$sql = "UPDATE " . USERS_TABLE . "
SET user_posts = user_posts $sign
WHERE user_id = $user_id";
if ( !($result = $db->sql_query($sql, END_TRANSACTION)) )
if ( !$db->sql_query($sql, END_TRANSACTION) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
@@ -505,14 +506,14 @@ function delete_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_
{
$sql = "DELETE FROM " . POSTS_TABLE . "
WHERE post_id = $post_id";
if ( !($db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
WHERE post_id = $post_id";
if ( !($db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
@@ -525,14 +526,14 @@ function delete_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_
$sql = "DELETE FROM " . TOPICS_TABLE . "
WHERE topic_id = $topic_id
OR topic_moved_id = $topic_id";
if ( !($db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
WHERE topic_id = $topic_id";
if ( !($db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
@@ -546,21 +547,21 @@ function delete_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_
{
$sql = "DELETE FROM " . VOTE_DESC_TABLE . "
WHERE topic_id = $topic_id";
if ( !($db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in deleting poll', '', __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM " . VOTE_RESULTS_TABLE . "
WHERE vote_id = $poll_id";
if ( !($db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in deleting poll', '', __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM " . VOTE_USERS_TABLE . "
WHERE vote_id = $poll_id";
if ( !($db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in deleting poll', '', __LINE__, __FILE__, $sql);
}
@@ -596,7 +597,7 @@ function user_notification($mode, &$post_data, &$forum_id, &$topic_id, &$post_id
{
$delete_sql = ( !$post_data['first_post'] && !$post_data['last_post'] ) ? " AND user_id = " . $userdata['user_id'] : '';
$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " WHERE topic_id = $topic_id" . $delete_sql;
if ( !($result = $db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not change topic notify data', '', __LINE__, __FILE__, $sql);
}
@@ -646,7 +647,7 @@ function user_notification($mode, &$post_data, &$forum_id, &$topic_id, &$post_id
$server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
$server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/';
$email_headers = 'From: ' . $board_config['board_email'] . "\nReturn-Path: " . $board_config['board_email'] . "\r\n";
$email_headers = 'From: ' . $board_config['board_email'] . "\r\nReturn-Path: " . $board_config['board_email'] . "\r\n";
$update_watched_sql = '';
if ( $row = $db->sql_fetchrow($result) )
@@ -659,7 +660,7 @@ function user_notification($mode, &$post_data, &$forum_id, &$topic_id, &$post_id
{
$emailer->use_template('topic_notify', $row['user_lang']);
$emailer->email_address($row['user_email']);
$emailer->set_subject();//$lang['Topic_reply_notification']
$emailer->set_subject();
$emailer->extra_headers($email_headers);
$emailer->assign_vars(array(
@@ -707,7 +708,7 @@ function user_notification($mode, &$post_data, &$forum_id, &$topic_id, &$post_id
$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
WHERE topic_id = $topic_id
AND user_id = " . $userdata['user_id'];
if ( !$result = $db->sql_query($sql) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not delete topic watch information', '', __LINE__, __FILE__, $sql);
}
@@ -716,7 +717,7 @@ function user_notification($mode, &$post_data, &$forum_id, &$topic_id, &$post_id
{
$sql = "INSERT INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
VALUES (" . $userdata['user_id'] . ", $topic_id, 0)";
if ( !($result = $db->sql_query($sql)) )
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not insert topic watch information', '', __LINE__, __FILE__, $sql);
}

View File

@@ -94,15 +94,10 @@ if ( $result = $db->sql_query($sql) )
include($phpbb_root_path . 'includes/emailer.'.$phpEx);
$emailer = new emailer($board_config['smtp_delivery']);
$email_headers = 'From: ' . $userdata['user_email'] . "\n";
if ( !empty($HTTP_POST_VARS['cc_email']) )
{
$email_headers .= "Cc: " . $userdata['user_email'] . "\n";
}
$email_headers .= 'Return-Path: ' . $userdata['user_email'] . "\n";
$email_headers .= 'X-AntiAbuse: Board servername - ' . $server_name . "\n";
$email_headers .= 'X-AntiAbuse: User_id - ' . $userdata['user_id'] . "\n";
$email_headers .= 'X-AntiAbuse: Username - ' . $userdata['username'] . "\n";
$email_headers = 'Return-Path: ' . $userdata['user_email'] . "\r\nFrom: " . $userdata['user_email'] . "\r\n";
$email_headers .= 'X-AntiAbuse: Board servername - ' . $server_name . "\r\n";
$email_headers .= 'X-AntiAbuse: User_id - ' . $userdata['user_id'] . "\r\n";
$email_headers .= 'X-AntiAbuse: Username - ' . $userdata['username'] . "\r\n";
$email_headers .= 'X-AntiAbuse: User IP - ' . decode_ip($user_ip) . "\r\n";
$emailer->use_template('profile_send_email', $user_lang);
@@ -120,6 +115,25 @@ if ( $result = $db->sql_query($sql) )
$emailer->send();
$emailer->reset();
if ( !empty($HTTP_POST_VARS['cc_email']) )
{
$email_headers = 'Return-Path: ' . $userdata['user_email'] . "\r\nFrom: " . $userdata['user_email'] . "\r\n";
$emailer->use_template('profile_send_email');
$emailer->email_address($userdata['user_email']);
$emailer->set_subject($subject);
$emailer->extra_headers($email_headers);
$emailer->assign_vars(array(
'SITENAME' => $board_config['sitename'],
'BOARD_EMAIL' => $board_config['board_email'],
'FROM_USERNAME' => $userdata['username'],
'TO_USERNAME' => $username,
'MESSAGE' => $message)
);
$emailer->send();
$emailer->reset();
}
$template->assign_vars(array(
'META' => '<meta http-equiv="refresh" content="5;url=' . append_sid("index.$phpEx") . '">')
);