function pa_mail($to, $type, $array_of_data, $from = DEFAULT_SENDER) { global $path_prefix; global $network_info; global $base_url; $container_html = 'default_email_container.tpl'; if (empty($from)) { $from = DEFAULT_SENDER; } // getting email data ie subject and message for the specified type $type // here $array_of_data will be containing actual data to be replaced in subject and message frame $email_data = EmailMessages::get($type, $array_of_data); $subject = $email_data['subject']; $message = $email_data['message']; // patching up message and subject in the email container $email_container =& new Template($path_prefix . '/web/Themes/Beta/email_container/' . $container_html); $email_container->set('subject', $subject); $email_container->set('message', $message); // actual message to be sent through the mail $message = $email_container->fetch(); $headers = "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=iso-8859-1\r\n" . "From: {$from}"; // if you want to test the e-mail system, set global // $mail_testing_callback to point to your own function, that // behaves like mail(). global $mail_testing_callback; $mail_func = $mail_testing_callback ? $mail_testing_callback : "mail"; $check = call_user_func($mail_func, $to, $subject, $message, $headers); if ($check == FALSE) { throw new PAException(MAIL_FUNCTION_FAILED, "Mail is not sent due to some internal server problem"); } else { return TRUE; } }
function generate_inner_html() { $email_list = EmailMessages::get_email_list(); $inner_template = NULL; $inner_template = dirname(__FILE__) . '/center_inner_html.tpl'; $obj_inner_template =& new Template($inner_template); $obj_inner_template->set('email_list', $email_list); $obj_inner_template->set('subject', $this->subject); $obj_inner_template->set('message', $this->message); $obj_inner_template->set('configurable_variables', $this->configurable_variables); $obj_inner_template->set('preview', $this->preview_msg); $inner_html = $obj_inner_template->fetch(); return $inner_html; }
function pa_mail($to, $type, $array_of_data, $from = DEFAULT_SENDER) { global $default_sender; $container_html = 'default_email_container.tpl'; if (empty($from)) { $from = DEFAULT_SENDER; } // getting email data ie subject and message for the specified type $type // here $array_of_data will be containing actual data to be replaced in subject and message frame $email_data = EmailMessages::get($type, $array_of_data); $subject = $email_data['subject']; $message = $email_data['message']; // patching up message and subject in the email container $email_container = new Template('config/email_containers/' . $container_html); $email_container->set('subject', $subject); $email_container->set('message', $message); // actual message to be sent through the mail $body = $email_container->fetch(); //making the url relative. $body = str_replace(PA::$url . '/images', 'images', $body); //making the user picture or the other such files path relative. $body = str_replace(PA::$url . '/files', 'files', $body); $mail = new PHPMailer(); $body = eregi_replace("[\\]", '', $body); $subject = eregi_replace("[\\]", '', $subject); // $mail->Sender = DEFAULT_SENDER; $mail->From = $mail->FromName = $default_sender; $mail->Subject = $subject; $mail->AltBody = strip_tags($body); $mail->MsgHTML($body); $mail->AddAddress($to, $to); // echo "<pre>".print_r($mail,1)."</pre>"; if (!$mail->Send()) { // echo "<pre>".print_r($mail,1)."</pre>";exit; throw new CNException(MAIL_FUNCTION_FAILED, "Mail is not sent due to PHPMailer error: " . $mail->ErrorInfo); } else { return TRUE; } }
/** !! * Gather the list of all email templates to be displayed on the drop down * menu by calling { @link getEmailContainers() } and placing it in * { @link $template_list }. Once a template has been selected create objects * to store all information for the email such as author and subject and place * them into ( @link $obj_inner_template }. * @return string $inner_html all the html to be displayed in the email, * gathered by setting this equal to { @link $obj_inner_template } */ function generate_inner_html() { if (!empty($_GET['template'])) { $this->template = $_GET['template']; } $tiny = new TinyMCE('medium'); $email_list = EmailMessages::get_email_list(); $template_list = $this->getEmailContainers(PA::$config_path . "/email_containers"); $inner_template = NULL; $inner_template = PA::$blockmodule_path . '/' . get_class($this) . '/center_inner_html.tpl'; $obj_inner_template = new Template($inner_template); $obj_inner_template->set('email_list', $email_list); $obj_inner_template->set('template_list', $template_list); $obj_inner_template->set('subject', $this->subject); $obj_inner_template->set('message', $this->message); $obj_inner_template->set('category', $this->category); $obj_inner_template->set('template', $this->template); $obj_inner_template->set('description', $this->description); $obj_inner_template->set('configurable_variables', $this->configurable_variables); $obj_inner_template->set('preview', $this->preview_msg); $obj_inner_template->set_object('tiny_mce', $tiny); $inner_html = $obj_inner_template->fetch(); return $inner_html; }
<legend><?php echo Yii::t("Bootstrap", "LIST.EmailMessages"); ?> </legend> <?php $assetsDir = Yii::app()->basePath; $labels = EmailMessages::model()->attributeLabels(); echo '<a href="/admin/' . Yii::app()->controller->module->id . '/' . Yii::app()->controller->id . '/create" class="btn" style="margin-bottom:20px;">Добавить</a>'; $this->widget('bootstrap.widgets.TbExtendedGridView', array('id' => 'email-messages-grid', 'template' => "{items}\n{pager}", 'enableHistory' => true, 'dataProvider' => $model->with("user")->search(), 'filter' => null, 'columns' => array(array('header' => $labels["id"], 'name' => "id"), array('header' => $labels["user_id"], 'name' => 'user_id', 'value' => '$data->user ? $data->user->username : ""', 'filter' => CHtml::listData(User::model()->findAll(array('order' => 'username')), 'id', 'username')), array('header' => $labels["to_email"], 'name' => "to_email"), array('header' => $labels["title"], 'name' => "title"), array('header' => $labels["status"], 'name' => "status", 'value' => 'EmailMessages::model()->getDownliststatus($data->status)'), array('header' => $labels["send_date"], 'name' => "send_date", 'value' => 'date("d-m-Y h:m:s", strtotime($data->send_date))'), array('header' => $labels["created_at"], 'name' => "created_at", 'value' => 'date("d-m-Y h:m:s", strtotime($data->created_at))'), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{update} {delete}', 'buttons' => array('update' => array('label' => yii::t('Bootstrap', 'PHRASE.UPDATE'), 'url' => 'CHtml::normalizeUrl(array("update", "id" => $data->id))', 'options' => array()), 'delete' => array('label' => yii::t('Bootstrap', 'PHRASE.DELETE'), 'options' => array())), 'htmlOptions' => array('style' => 'white-space: nowrap')))));
// $email_messages has been defined in default_email_messages page foreach ($email_messages as $email_msgs => $data) { if ($data['type'] == $email_type) { $subject = $data['subject']; $message_file = $data['message']; $EmailMessageFile = "{$path_prefix}/web/includes/email_msg_text/{$message_file}"; $fh = fopen($EmailMessageFile, 'r'); if (filesize($EmailMessageFile)) { $theData = fread($fh, filesize($EmailMessageFile)); $theData = mysql_escape_string($theData); fclose($fh); } $message = $theData; } } $email = new EmailMessages(); $email->subject = $subject; $email->message = $message; $email->type = $email_type; $email->update(); $subject = $message = $configurable_variables = NULL; header("location: configure_email.php?msg=13002&email_type={$email_type}"); } else { if (!empty($_POST['preview_email'])) { filter_all_post($_POST); $subject = $_POST['subject']; $message = $_POST['email_message']; // say $container_html is '/default_email_container.tpl' $container_html = 'default_email_container.tpl'; $email_container =& new Template($path_prefix . '/web/Themes/Beta/email_container/' . $container_html); $email_container->set('subject', $subject);
function switch_destination($destination) { $this->no_id = ""; if (empty($this->mail_type)) { $this->mail_type = ''; //none } if (empty($this->network_owner)) { // sometime group_owner param passed as recepient in this var - VERY BAD! $net_owner = new User(); $net_owner->load((int) PA::$network_info->owner_id); $this->network_owner = $net_owner->login_name; } // checking whether subject or message is set or not $msg_data = EmailMessages::get($this->mail_type, $this->mail_sub_msg_array); $this->subject = @$msg_data['subject']; $this->message = @$msg_data['message']; if (empty($this->subject)) { $this->subject = 'none'; } if (empty($this->message)) { $this->message = 'Message for internal mail is under construction. <br /><br /> We\'ll back with appropriate message soon!!!'; } if ($this->mail_type == 'friend_request') { $mail_from = $_SESSION['user']['email']; } switch ($destination) { case NET_EMAIL: //external mail $check = pa_mail($this->to, $this->mail_type, $this->mail_sub_msg_array, @$mail_from); break; case NET_MSG: //internal messageing Message::add_message($this->from, $this->no_id, $this->network_owner, $this->subject, $this->message); $sender = new User(); $sender->load((int) $this->from); $sender_id = $sender->user_id; $sender_name = $sender->login_name; $recipient_id = User::map_logins_to_ids($this->network_owner); $_sender_url = url_for('user_blog', array('login' => $sender->login_name)); $sender_url = "<a href=\"{$_sender_url}\">{$_sender_url}</a>"; $my_messages_url = '<a href="' . PA::$url . '/' . FILE_MYMESSAGE . '">' . PA::$url . '/' . FILE_MYMESSAGE . '</a>'; $recipient_obj = new User(); foreach ($recipient_id as $key => $value) { $recipient_obj->load((int) $value); } // send msg waiting blink message $params = array('first_name_sender' => $sender_name, 'first_name_recipient' => $recipient_obj->first_name, 'sender_id' => $sender_id, 'recipient_id' => $recipient_obj->user_id, 'recipient_email' => $recipient_obj->email, 'sender_url' => $sender_url, 'my_messages_url' => $my_messages_url, 'config_site_name' => PA::$site_name); auto_email_notification('msg_waiting', $params); break; case NET_BOTH: // via both option // FIXME: $mail_from seems not be set on peepagg try { $check = pa_mail($this->to, $this->mail_type, $this->mail_sub_msg_array, @$mail_from); } catch (PAEXception $e) { Logger::log(__FILE__ . ": pa_mail: " . $e->getMessage()); } Message::add_message($this->from, $this->no_id, $this->network_owner, $this->subject, $this->message); $sender = new User(); $sender->load((int) $this->from); $sender_id = $sender->user_id; $sender_name = $sender->login_name; $recipient_id = User::map_logins_to_ids($this->network_owner); $_sender_url = url_for('user_blog', array('login' => $sender->login_name)); $sender_url = "<a href=\"{$_sender_url}\">{$_sender_url}</a>"; $my_messages_url = '<a href="' . PA::$url . '/' . FILE_MYMESSAGE . '">' . PA::$url . '/' . FILE_MYMESSAGE . '</a>'; $recipient_obj = new User(); foreach ($recipient_id as $key => $value) { $recipient_obj->load((int) $value); } // send msg waiting blink message $params = array('first_name_sender' => $sender_name, 'first_name_recipient' => $recipient_obj->first_name, 'sender_id' => $sender_id, 'recipient_id' => $recipient_obj->user_id, 'recipient_email' => $recipient_obj->email, 'sender_url' => $sender_url, 'my_messages_url' => $my_messages_url, 'config_site_name' => PA::$site_name); // chnaged by Martin: this is NET_BOTH, the user is already recieving it as email // so why do we also trigger the ms_waiting here? // auto_email_notification('msg_waiting', $params); break; } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = EmailMessages::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function load($type) { $e_msg = EmailMessages::get($type); if (empty($this->subject)) { $this->subject = $e_msg['subject']; } if (empty($this->message)) { $this->message = $e_msg['message']; } if (empty($this->category)) { $this->message = $e_msg['category']; } if (empty($this->template)) { $this->message = $e_msg['template']; } if (empty($this->description)) { $this->description = $e_msg['description']; } if (empty($this->configurable_variables)) { $this->configurable_variables = $e_msg['configurable_variables']; } }
function switch_destination($destination) { global $to, $mail_type, $mail_sub_msg_array, $from, $no_id, $network_owner, $subject, $message, $config_site_name; // these should be instance vars, not globals! $no_id = ""; if (empty($mail_type)) { $mail_type = ''; //none } // checking whether subject or message is set or not $msg_data = EmailMessages::get($mail_type, $mail_sub_msg_array); $subject = $msg_data['subject']; $message = $msg_data['message']; if (empty($subject)) { $subject = 'none'; } if (empty($message)) { $message = 'Message for internal mail is under construction. <br /><br /> We\'ll back with appropriate message soon!!!'; } if ($mail_type == 'friend_request') { $mail_from = $_SESSION['user']['email']; } switch ($destination) { case NET_EMAIL: //external mail $check = pa_mail($to, $mail_type, $mail_sub_msg_array, @$mail_from); break; case NET_MSG: //internal messageing Message::add_message($from, $no_id, $network_owner, $subject, $message); $sender = new User(); $sender->load((int) $from); $sender_id = $sender->user_id; $sender_name = $sender->login_name; $recipient_id = User::map_logins_to_ids($network_owner); $sender_url = url_for('user_blog', array('login' => $sender->login_name)); $my_messages_url = PA::$url . '/' . FILE_MYMESSAGE; $recipient_obj = new User(); foreach ($recipient_id as $key => $value) { $recipient_obj->load((int) $value); } // send msg waiting blink message $params = array('first_name_sender' => $sender_name, 'first_name_recipient' => $recipient_obj->first_name, 'sender_id' => $sender_id, 'recipient_id' => $recipient_obj->user_id, 'recipient_email' => $recipient_obj->email, 'sender_url' => $sender_url, 'my_messages_url' => $my_messages_url, 'config_site_name' => $config_site_name); auto_email_notification('msg_waiting', $params); break; case NET_BOTH: // via both option // FIXME: $mail_from seems not be set on peepagg $check = pa_mail($to, $mail_type, $mail_sub_msg_array, @$mail_from); Message::add_message($from, $no_id, $network_owner, $subject, $message); $sender = new User(); $sender->load((int) $from); $sender_id = $sender->user_id; $sender_name = $sender->login_name; $recipient_id = User::map_logins_to_ids($network_owner); $sender_url = url_for('user_blog', array('login' => $sender->login_name)); $my_messages_url = PA::$url . '/' . FILE_MYMESSAGE; $recipient_obj = new User(); foreach ($recipient_id as $key => $value) { $recipient_obj->load((int) $value); } // send msg waiting blink message $params = array('first_name_sender' => $sender_name, 'first_name_recipient' => $recipient_obj->first_name, 'sender_id' => $sender_id, 'recipient_id' => $recipient_obj->user_id, 'recipient_email' => $recipient_obj->email, 'sender_url' => $sender_url, 'my_messages_url' => $my_messages_url, 'config_site_name' => $config_site_name); auto_email_notification('msg_waiting', $params); break; } }
function saveEmail(&$err_msg, $save_to_file = false) { global $email_type; $error = false; $res = false; filter_all_post($_POST); $mandatory_fields = array('subject' => 'Caption', "description" => "Description", 'email_message' => 'Message'); foreach ($mandatory_fields as $key => $value) { if (empty($_POST[$key])) { $error = true; $err_msg[] = $value . ' can\'t be empty.'; } } if (!$error) { $res = true; $err_msg = 13001; $email = new EmailMessages(); $email->subject = $_POST['subject']; $email->category = $_POST['category']; $email->template = $_POST['template']; $email->message = $_POST['email_message']; $email->description = $_POST['description']; $email->type = $email_type; $email->update(); if ($save_to_file) { try { $email->saveToFile(); } catch (Exception $e) { $error = true; $err_msg = $e->getMessage(); $res = false; } } } return $res; }