2 /***************************************************************************
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: usercp_email.php,v 1.7.2.14 2006/12/16 13:11:26 acydburn Exp $
12 ***************************************************************************/
14 /***************************************************************************
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
22 ***************************************************************************/
24 if ( !defined('IN_PHPBB') )
26 die("Hacking attempt");
30 // Is send through board enabled? No, return to index
31 if (!$board_config['board_email_form'])
33 redirect(append_sid("index.$phpEx", true));
36 if ( !empty($HTTP_GET_VARS[POST_USERS_URL]) || !empty($HTTP_POST_VARS[POST_USERS_URL]) )
38 $user_id = ( !empty($HTTP_GET_VARS[POST_USERS_URL]) ) ? intval($HTTP_GET_VARS[POST_USERS_URL]) : intval($HTTP_POST_VARS[POST_USERS_URL]);
42 message_die(GENERAL_MESSAGE, $lang['No_user_specified']);
45 if ( !$userdata['session_logged_in'] )
47 redirect(append_sid("login.$phpEx?redirect=profile.$phpEx&mode=email&" . POST_USERS_URL . "=$user_id", true));
50 $sql = "SELECT username, user_email, user_viewemail, user_lang
51 FROM " . USERS_TABLE . "
52 WHERE user_id = $user_id";
53 if ( $result = $db->sql_query($sql) )
55 if ( $row = $db->sql_fetchrow($result) )
58 $username = $row['username'];
59 $user_email = $row['user_email'];
60 $user_lang = $row['user_lang'];
62 if ( $row['user_viewemail'] || $userdata['user_level'] == ADMIN )
64 if ( time() - $userdata['user_emailtime'] < $board_config['flood_interval'] )
66 message_die(GENERAL_MESSAGE, $lang['Flood_email_limit']);
69 if ( isset($HTTP_POST_VARS['submit']) )
73 if ( !empty($HTTP_POST_VARS['subject']) )
75 $subject = trim(stripslashes($HTTP_POST_VARS['subject']));
80 $error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['Empty_subject_email'] : $lang['Empty_subject_email'];
83 if ( !empty($HTTP_POST_VARS['message']) )
85 $message = trim(stripslashes($HTTP_POST_VARS['message']));
90 $error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['Empty_message_email'] : $lang['Empty_message_email'];
95 $sql = "UPDATE " . USERS_TABLE . "
96 SET user_emailtime = " . time() . "
97 WHERE user_id = " . $userdata['user_id'];
98 if ( $result = $db->sql_query($sql) )
100 include($phpbb_root_path . 'includes/emailer.'.$phpEx);
101 $emailer = new emailer($board_config['smtp_delivery']);
103 $emailer->from($userdata['user_email']);
104 $emailer->replyto($userdata['user_email']);
106 $email_headers = 'X-AntiAbuse: Board servername - ' . $server_name . "\n";
107 $email_headers .= 'X-AntiAbuse: User_id - ' . $userdata['user_id'] . "\n";
108 $email_headers .= 'X-AntiAbuse: Username - ' . $userdata['username'] . "\n";
109 $email_headers .= 'X-AntiAbuse: User IP - ' . decode_ip($user_ip) . "\n";
111 $emailer->use_template('profile_send_email', $user_lang);
112 $emailer->email_address($user_email);
113 $emailer->set_subject($subject);
114 $emailer->extra_headers($email_headers);
116 $emailer->assign_vars(array(
117 'SITENAME' => $board_config['sitename'],
118 'BOARD_EMAIL' => $board_config['board_email'],
119 'FROM_USERNAME' => $userdata['username'],
120 'TO_USERNAME' => $username,
121 'MESSAGE' => $message)
126 if ( !empty($HTTP_POST_VARS['cc_email']) )
128 $emailer->from($userdata['user_email']);
129 $emailer->replyto($userdata['user_email']);
130 $emailer->use_template('profile_send_email');
131 $emailer->email_address($userdata['user_email']);
132 $emailer->set_subject($subject);
134 $emailer->assign_vars(array(
135 'SITENAME' => $board_config['sitename'],
136 'BOARD_EMAIL' => $board_config['board_email'],
137 'FROM_USERNAME' => $userdata['username'],
138 'TO_USERNAME' => $username,
139 'MESSAGE' => $message)
145 $template->assign_vars(array(
146 'META' => '<meta http-equiv="refresh" content="5;url=' . append_sid("index.$phpEx") . '">')
149 $message = $lang['Email_sent'] . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
151 message_die(GENERAL_MESSAGE, $message);
155 message_die(GENERAL_ERROR, 'Could not update last email time', '', __LINE__, __FILE__, $sql);
160 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
162 $template->set_filenames(array(
163 'body' => 'profile_send_email.tpl')
165 make_jumpbox('viewforum.'.$phpEx);
169 $template->set_filenames(array(
170 'reg_header' => 'error_body.tpl')
172 $template->assign_vars(array(
173 'ERROR_MESSAGE' => $error_msg)
175 $template->assign_var_from_handle('ERROR_BOX', 'reg_header');
178 $template->assign_vars(array(
179 'USERNAME' => $username,
181 'S_HIDDEN_FIELDS' => '',
182 'S_POST_ACTION' => append_sid("profile.$phpEx?mode=email&" . POST_USERS_URL . "=$user_id"),
184 'L_SEND_EMAIL_MSG' => $lang['Send_email_msg'],
185 'L_RECIPIENT' => $lang['Recipient'],
186 'L_SUBJECT' => $lang['Subject'],
187 'L_MESSAGE_BODY' => $lang['Message_body'],
188 'L_MESSAGE_BODY_DESC' => $lang['Email_message_desc'],
189 'L_EMPTY_SUBJECT_EMAIL' => $lang['Empty_subject_email'],
190 'L_EMPTY_MESSAGE_EMAIL' => $lang['Empty_message_email'],
191 'L_OPTIONS' => $lang['Options'],
192 'L_CC_EMAIL' => $lang['CC_email'],
193 'L_SPELLCHECK' => $lang['Spellcheck'],
194 'L_SEND_EMAIL' => $lang['Send_email'])
197 $template->pparse('body');
199 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
203 message_die(GENERAL_MESSAGE, $lang['User_prevent_email']);
208 message_die(GENERAL_MESSAGE, $lang['User_not_exist']);
213 message_die(GENERAL_ERROR, 'Could not select user data', '', __LINE__, __FILE__, $sql);