How to use send method of mail class

Best Atoum code snippet using mail.send

notification_by_mail.php

Source:notification_by_mail.php Github

copy

Full Screen

...45// +-----------------------------------------------------------------------+46// | functions |47// +-----------------------------------------------------------------------+48/*49 * Do timeout treatment in order to finish to send mails50 *51 * @param $post_keyname: key of check_key post array52 * @param check_key_treated: array of check_key treated53 * @return none54 */55function do_timeout_treatment($post_keyname, $check_key_treated = array())56{57 global $env_nbm, $base_url, $page, $must_repost;58 if ($env_nbm['is_sendmail_timeout'])59 {60 if (isset($_POST[$post_keyname]))61 {62 $post_count = count($_POST[$post_keyname]);63 $treated_count = count($check_key_treated);64 if ($treated_count != 0)65 {66 $time_refresh = ceil((get_moment() - $env_nbm['start_time']) * $post_count / $treated_count);67 }68 else69 {70 $time_refresh = 0;71 }72 $_POST[$post_keyname] = array_diff($_POST[$post_keyname], $check_key_treated);73 $must_repost = true;74 $page['errors'][] = l10n_dec(75 'Execution time is out, treatment must be continue [Estimated time: %d second].',76 'Execution time is out, treatment must be continue [Estimated time: %d seconds].',77 $time_refresh78 );79 }80 }81}82/*83 * Get the authorized_status for each tab84 * return corresponding status85 */86function get_tab_status($mode)87{88 $result = ACCESS_WEBMASTER;89 switch ($mode)90 {91 case 'param':92 case 'subscribe':93 $result = ACCESS_WEBMASTER;94 break;95 case 'send':96 $result = ACCESS_ADMINISTRATOR;97 break;98 default:99 $result = ACCESS_WEBMASTER;100 break;101 }102 return $result;103}104/*105 * Inserting News users106 */107function insert_new_data_user_mail_notification()108{109 global $conf, $page, $env_nbm;110 // Set null mail_address empty111 $query = '112update113 '.USERS_TABLE.'114set115 '.$conf['user_fields']['email'].' = null116where117 trim('.$conf['user_fields']['email'].') = \'\';';118 pwg_query($query);119 // null mail_address are not selected in the list120 $query = '121select122 u.'.$conf['user_fields']['id'].' as user_id,123 u.'.$conf['user_fields']['username'].' as username,124 u.'.$conf['user_fields']['email'].' as mail_address125from126 '.USERS_TABLE.' as u left join '.USER_MAIL_NOTIFICATION_TABLE.' as m on u.'.$conf['user_fields']['id'].' = m.user_id127where128 u.'.$conf['user_fields']['email'].' is not null and129 m.user_id is null130order by131 user_id;';132 $result = pwg_query($query);133 if (pwg_db_num_rows($result) > 0)134 {135 $inserts = array();136 $check_key_list = array();137 while ($nbm_user = pwg_db_fetch_assoc($result))138 {139 // Calculate key140 $nbm_user['check_key'] = find_available_check_key();141 // Save key142 $check_key_list[] = $nbm_user['check_key'];143 // Insert new nbm_users144 $inserts[] = array(145 'user_id' => $nbm_user['user_id'],146 'check_key' => $nbm_user['check_key'],147 'enabled' => 'false' // By default if false, set to true with specific functions148 );149 $page['infos'][] = l10n(150 'User %s [%s] added.',151 stripslashes($nbm_user['username']),152 $nbm_user['mail_address']153 );154 }155 // Insert new nbm_users156 mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts);157 // Update field enabled with specific function158 $check_key_treated = do_subscribe_unsubscribe_notification_by_mail159 (160 true,161 $conf['nbm_default_value_user_enabled'],162 $check_key_list163 );164 // On timeout simulate like tabsheet send165 if ($env_nbm['is_sendmail_timeout'])166 {167 $quoted_check_key_list = quote_check_key_list(array_diff($check_key_list, $check_key_treated));168 if (count($quoted_check_key_list) != 0 )169 {170 $query = 'delete from '.USER_MAIL_NOTIFICATION_TABLE.' where check_key in ('.implode(",", $quoted_check_key_list).');';171 $result = pwg_query($query);172 redirect($base_url.get_query_string_diff(array(), false), l10n('Operation in progress')."\n".l10n('Please wait...'));173 }174 }175 }176}177/*178 * Apply global functions to mail content179 * return customize mail content rendered180 */181function render_global_customize_mail_content($customize_mail_content)182{183 global $conf;184 if ($conf['nbm_send_html_mail'] and !(strpos($customize_mail_content, '<') === 0))185 {186 // On HTML mail, detects if the content are HTML format.187 // If it's plain text format, convert content to readable HTML188 return nl2br(htmlspecialchars($customize_mail_content));189 }190 else191 {192 return $customize_mail_content;193 }194}195/*196 * Send mail for notification to all users197 * Return list of "selected" users for 'list_to_send'198 * Return list of "treated" check_key for 'send'199 */200function do_action_send_mail_notification($action = 'list_to_send', $check_key_list = array(), $customize_mail_content = '')201{202 global $conf, $page, $user, $lang_info, $lang, $env_nbm;203 $return_list = array();204 if (in_array($action, array('list_to_send', 'send')))205 {206 list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));207 $is_action_send = ($action == 'send');208 // disabled and null mail_address are not selected in the list209 $data_users = get_user_notifications('send', $check_key_list);210 // List all if it's define on options or on timeout211 $is_list_all_without_test = ($env_nbm['is_sendmail_timeout'] or $conf['nbm_list_all_enabled_users_to_send']);212 // Check if exist news to list user or send mails213 if ((!$is_list_all_without_test) or ($is_action_send))214 {215 if (count($data_users) > 0)216 {217 $datas = array();218 if (!isset($customize_mail_content))219 {220 $customize_mail_content = $conf['nbm_complementary_mail_content'];221 }222 $customize_mail_content = 223 trigger_change('nbm_render_global_customize_mail_content', $customize_mail_content);224 // Prepare message after change language225 if ($is_action_send)226 {227 $msg_break_timeout = l10n('Time to send mail is limited. Others mails are skipped.');228 }229 else230 {231 $msg_break_timeout = l10n('Prepared time for list of users to send mail is limited. Others users are not listed.');232 }233 // Begin nbm users environment234 begin_users_env_nbm($is_action_send);235 foreach ($data_users as $nbm_user)236 {237 if ((!$is_action_send) and check_sendmail_timeout())238 {239 // Stop fill list on 'list_to_send', if the quota is override240 $page['infos'][] = $msg_break_timeout;241 break;242 }243 if (($is_action_send) and check_sendmail_timeout())244 {245 // Stop fill list on 'send', if the quota is override246 $page['errors'][] = $msg_break_timeout;247 break;248 }249 // set env nbm user250 set_user_on_env_nbm($nbm_user, $is_action_send);251 if ($is_action_send)252 {253 $auth = null;254 $add_url_params = array();255 256 $auth_key = create_user_auth_key($nbm_user['user_id'], $nbm_user['status']);257 258 if ($auth_key !== false)259 {260 $auth = $auth_key['auth_key'];261 $add_url_params['auth'] = $auth;262 }263 264 set_make_full_url();265 // Fill return list of "treated" check_key for 'send'266 $return_list[] = $nbm_user['check_key'];267 if ($conf['nbm_send_detailed_content'])268 {269 $news = news($nbm_user['last_send'], $dbnow, false, $conf['nbm_send_html_mail'], $auth);270 $exist_data = count($news) > 0;271 }272 else273 {274 $exist_data = news_exists($nbm_user['last_send'], $dbnow);275 }276 if ($exist_data)277 {278 $subject = '['.$conf['gallery_title'].'] '.l10n('New photos added');279 // Assign current var for nbm mail280 assign_vars_nbm_mail_content($nbm_user);281 if (!is_null($nbm_user['last_send']))282 {283 $env_nbm['mail_template']->assign284 (285 'content_new_elements_between',286 array287 (288 'DATE_BETWEEN_1' => $nbm_user['last_send'],289 'DATE_BETWEEN_2' => $dbnow,290 )291 );292 }293 else294 {295 $env_nbm['mail_template']->assign296 (297 'content_new_elements_single',298 array299 (300 'DATE_SINGLE' => $dbnow,301 )302 );303 }304 if ($conf['nbm_send_detailed_content'])305 {306 $env_nbm['mail_template']->assign('global_new_lines', $news);307 }308 $nbm_user_customize_mail_content = 309 trigger_change('nbm_render_user_customize_mail_content',310 $customize_mail_content, $nbm_user);311 if (!empty($nbm_user_customize_mail_content))312 {313 $env_nbm['mail_template']->assign314 (315 'custom_mail_content', $nbm_user_customize_mail_content316 );317 }318 if ($conf['nbm_send_html_mail'] and $conf['nbm_send_recent_post_dates'])319 {320 $recent_post_dates = get_recent_post_dates_array(321 $conf['recent_post_dates']['NBM']);322 foreach ($recent_post_dates as $date_detail)323 {324 $env_nbm['mail_template']->append325 (326 'recent_posts',327 array328 (329 'TITLE' => get_title_recent_post_date($date_detail),330 'HTML_DATA' => get_html_description_recent_post_date($date_detail, $auth)331 )332 );333 }334 }335 $env_nbm['mail_template']->assign336 (337 array338 (339 'GOTO_GALLERY_TITLE' => $conf['gallery_title'],340 'GOTO_GALLERY_URL' => add_url_params(get_gallery_home_url(), $add_url_params),341 'SEND_AS_NAME' => $env_nbm['send_as_name'],342 )343 );344 345 $ret = pwg_mail(346 array(347 'name' => stripslashes($nbm_user['username']),348 'email' => $nbm_user['mail_address'],349 ),350 array(351 'from' => $env_nbm['send_as_mail_formated'],352 'subject' => $subject,353 'email_format' => $env_nbm['email_format'],354 'content' => $env_nbm['mail_template']->parse('notification_by_mail', true),355 'content_format' => $env_nbm['email_format'],356 'auth_key' => $auth,357 )358 );359 if ($ret)360 {361 inc_mail_sent_success($nbm_user);362 $datas[] = array(363 'user_id' => $nbm_user['user_id'],364 'last_send' => $dbnow365 );366 }367 else368 {369 inc_mail_sent_failed($nbm_user);370 }371 unset_make_full_url();372 }373 }374 else375 {376 if (news_exists($nbm_user['last_send'], $dbnow))377 {378 // Fill return list of "selected" users for 'list_to_send'379 $return_list[] = $nbm_user;380 }381 }382 // unset env nbm user383 unset_user_on_env_nbm();384 }385 // Restore nbm environment386 end_users_env_nbm();387 if ($is_action_send)388 {389 mass_updates(390 USER_MAIL_NOTIFICATION_TABLE,391 array(392 'primary' => array('user_id'),393 'update' => array('last_send')394 ),395 $datas396 );397 display_counter_info();398 }399 }400 else401 {402 if ($is_action_send)403 {404 $page['errors'][] = l10n('No user to send notifications by mail.');405 }406 }407 }408 else409 {410 // Quick List, don't check news411 // Fill return list of "selected" users for 'list_to_send'412 $return_list = $data_users;413 }414 }415 // Return list of "selected" users for 'list_to_send'416 // Return list of "treated" check_key for 'send'417 return $return_list;418}419// +-----------------------------------------------------------------------+420// | Main |421// +-----------------------------------------------------------------------+422if (!isset($_GET['mode']))423{424 $page['mode'] = 'send';425}426else427{428 $page['mode'] = $_GET['mode'];429}430// +-----------------------------------------------------------------------+431// | Check Access and exit when user status is not ok |432// +-----------------------------------------------------------------------+433check_status(get_tab_status($page['mode']));434// +-----------------------------------------------------------------------+435// | Add event handler |436// +-----------------------------------------------------------------------+437add_event_handler('nbm_render_global_customize_mail_content', 'render_global_customize_mail_content');438trigger_notify('nbm_event_handler_added');439// +-----------------------------------------------------------------------+440// | Insert new users with mails |441// +-----------------------------------------------------------------------+442if (!isset($_POST) or (count($_POST) ==0))443{444 // No insert data in post mode445 insert_new_data_user_mail_notification();446}447// +-----------------------------------------------------------------------+448// | Treatment of tab post |449// +-----------------------------------------------------------------------+450switch ($page['mode'])451{452 case 'param' :453 {454 if (isset($_POST['param_submit']))455 {456 $updated_param_count = 0;457 // Update param458 $result = pwg_query('select param, value from '.CONFIG_TABLE.' where param like \'nbm\\_%\'');459 while ($nbm_user = pwg_db_fetch_assoc($result))460 {461 if (isset($_POST[$nbm_user['param']]))462 {463 $value = $_POST[$nbm_user['param']];464 $query = '465update466'.CONFIG_TABLE.'467set468 value = \''. str_replace("\'", "''", $value).'\'469where470 param = \''.$nbm_user['param'].'\';';471 pwg_query($query);472 $updated_param_count += 1;473 }474 }475 $page['infos'][] = l10n_dec(476 '%d parameter was updated.', '%d parameters were updated.',477 $updated_param_count478 );479 // Reload conf with new values480 load_conf_from_db('param like \'nbm\\_%\'');481 }482 }483 case 'subscribe' :484 {485 if (isset($_POST['falsify']) and isset($_POST['cat_true']))486 {487 $check_key_treated = unsubscribe_notification_by_mail(true, $_POST['cat_true']);488 do_timeout_treatment('cat_true', $check_key_treated);489 }490 else491 if (isset($_POST['trueify']) and isset($_POST['cat_false']))492 {493 $check_key_treated = subscribe_notification_by_mail(true, $_POST['cat_false']);494 do_timeout_treatment('cat_false', $check_key_treated);495 }496 break;497 }498 case 'send' :499 {500 if (isset($_POST['send_submit']) and isset($_POST['send_selection']) and isset($_POST['send_customize_mail_content']))501 {502 $check_key_treated = do_action_send_mail_notification('send', $_POST['send_selection'], stripslashes($_POST['send_customize_mail_content']));503 do_timeout_treatment('send_selection', $check_key_treated);504 }505 }506}507// +-----------------------------------------------------------------------+508// | template initialization |509// +-----------------------------------------------------------------------+510$template->set_filenames511(512 array513 (514 'double_select' => 'double_select.tpl',515 'notification_by_mail'=>'notification_by_mail.tpl'516 )517);518$template->assign519(520 array521 (522 'U_HELP' => get_root_url().'admin/popuphelp.php?page=notification_by_mail',523 'F_ACTION'=> $base_url.get_query_string_diff(array())524 )525);526if (is_autorize_status(ACCESS_WEBMASTER))527{528 // TabSheet529 $tabsheet = new tabsheet();530 $tabsheet->set_id('nbm');531 $tabsheet->select($page['mode']);532 $tabsheet->assign();533}534if ($must_repost)535{536 // Get name of submit button537 $repost_submit_name = '';538 if (isset($_POST['falsify']))539 {540 $repost_submit_name = 'falsify';541 }542 elseif (isset($_POST['trueify']))543 {544 $repost_submit_name = 'trueify';545 }546 elseif (isset($_POST['send_submit']))547 {548 $repost_submit_name = 'send_submit';549 }550 $template->assign('REPOST_SUBMIT_NAME', $repost_submit_name);551}552switch ($page['mode'])553{554 case 'param' :555 {556 $template->assign(557 $page['mode'],558 array(559 'SEND_HTML_MAIL' => $conf['nbm_send_html_mail'],560 'SEND_MAIL_AS' => $conf['nbm_send_mail_as'],561 'SEND_DETAILED_CONTENT' => $conf['nbm_send_detailed_content'],562 'COMPLEMENTARY_MAIL_CONTENT' => $conf['nbm_complementary_mail_content'],563 'SEND_RECENT_POST_DATES' => $conf['nbm_send_recent_post_dates'],564 ));565 break;566 }567 case 'subscribe' :568 {569 $template->assign( $page['mode'], true );570 $template->assign(571 array(572 'L_CAT_OPTIONS_TRUE' => l10n('Subscribed'),573 'L_CAT_OPTIONS_FALSE' => l10n('Unsubscribed')574 )575 );576 $data_users = get_user_notifications('subscribe');577 578 $opt_true = array();579 $opt_true_selected = array();580 $opt_false = array();581 $opt_false_selected = array();582 foreach ($data_users as $nbm_user)583 {584 if (get_boolean($nbm_user['enabled']))585 {586 $opt_true[ $nbm_user['check_key'] ] = stripslashes($nbm_user['username']).'['.$nbm_user['mail_address'].']';587 if ((isset($_POST['falsify']) and isset($_POST['cat_true']) and in_array($nbm_user['check_key'], $_POST['cat_true'])))588 {589 $opt_true_selected[] = $nbm_user['check_key'];590 }591 }592 else593 {594 $opt_false[ $nbm_user['check_key'] ] = stripslashes($nbm_user['username']).'['.$nbm_user['mail_address'].']';595 if (isset($_POST['trueify']) and isset($_POST['cat_false']) and in_array($nbm_user['check_key'], $_POST['cat_false']))596 {597 $opt_false_selected[] = $nbm_user['check_key'];598 }599 }600 }601 $template->assign( array(602 'category_option_true' => $opt_true,603 'category_option_true_selected' => $opt_true_selected,604 'category_option_false' => $opt_false,605 'category_option_false_selected' => $opt_false_selected,606 )607 );608 $template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');609 break;610 }611 case 'send' :612 {613 $tpl_var = array('users'=> array() );614 $data_users = do_action_send_mail_notification('list_to_send');615 $tpl_var['CUSTOMIZE_MAIL_CONTENT'] = 616 isset($_POST['send_customize_mail_content']) 617 ? stripslashes($_POST['send_customize_mail_content']) 618 : $conf['nbm_complementary_mail_content'];619 if (count($data_users))620 {621 foreach ($data_users as $nbm_user)622 {623 if (624 (!$must_repost) or // Not timeout, normal treatment625 (($must_repost) and in_array($nbm_user['check_key'], $_POST['send_selection'])) // Must be repost, show only user to send626 )627 {628 $tpl_var['users'][] = 629 array(630 'ID' => $nbm_user['check_key'],631 'CHECKED' => ( // not check if not selected, on init select<all632 isset($_POST['send_selection']) and // not init633 !in_array($nbm_user['check_key'], $_POST['send_selection']) // not selected634 ) ? '' : 'checked="checked"',635 'USERNAME'=> stripslashes($nbm_user['username']),636 'EMAIL' => $nbm_user['mail_address'],637 'LAST_SEND'=> $nbm_user['last_send']638 );639 }640 }641 }642 $template->assign($page['mode'], $tpl_var);643 if ($conf['auth_key_duration'] > 0)644 {645 $template->assign(646 'auth_key_duration',647 time_since(648 strtotime('now -'.$conf['auth_key_duration'].' second'),649 'second',650 null,651 false...

Full Screen

Full Screen

SMIT_Email.php

Source:SMIT_Email.php Github

copy

Full Screen

...32 * @param string $from (Optional) From email33 * @param string $from_name (Optional) From name email34 * @return Mixed35 */36 function send($to, $subject, $message, $from = '', $from_name = ''){37 if (!$this->active) return false;38 39 $transport = false; 40 41 if ($mailserver_host = config_item('mailserver_host')) {42 $mailserver_port = config_item('mailserver_port');43 $transport = Swift_SmtpTransport::newInstance($mailserver_host, $mailserver_port, 'ssl');44 45 if ( $username = config_item('mailserver_username') )46 $transport->setUsername( $username );47 48 if ( $password = config_item('mailserver_password') )49 $transport->setPassword( $password );50 }51 52 try{53 // Create the Transport54 if(!$transport) $transport = Swift_MailTransport::newInstance();55 else $transport = Swift_MailTransport::newInstance($transport);56 // Create the message57 $mail = Swift_Message::newInstance();58 // Give the message a subject59 $mail->setSubject($subject)60 ->setFrom(array($from => $from_name))61 ->setTo($to)62 ->setBody($message->plain)63 ->addPart($message->html, 'text/html');64 // Create the Mailer using your created Transport65 $mailer = Swift_Mailer::newInstance($transport);66 // Send the message67 $result = $mailer->send($mail); 68 69 return $result;70 }catch (Exception $e){71 // Should be database log in here72 smit_log('SEND_EMAIL', 'ERROR', $e->getMessage());73 }74 return false;75 }76 77 /**78 * Send email test function.79 * @return Mixed80 */81 function send_email_test( $to ) {82 if ( !$to ) return false;83 84 $message = 'This is test email using Swiftmailer.'; 85 $html_message = smit_notification_template($message);86 87 $mail_message = new stdClass();88 $mail_message->plain = $message;89 $mail_message->html = $html_message;90 91 return $this->send( $to, 'Test Email Swiftmailer', $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );92 }93 94 /**95 * Send email forgot password function.96 *97 * @param string $id_user (Required) ID User98 * @param string $password (Required) Password that forgot99 * @return Mixed100 */101 function send_email_forgot_password( $id_user, $password ) {102 if ( ! $user = smit_get_userdata_by_id( $id_user ) )103 return false;104 105 $message = trim( get_option('be_notif_forgot_password') );106 $message = str_replace("{%username%}", $user->username, $message);107 $message = str_replace("{%name%}", strtoupper($user->name), $message);108 $message = str_replace("{%password%}", $password, $message);109 110 $html_message = smit_notification_template_clear($message);111 112 $mail_message = new stdClass();113 $mail_message->plain = $message;114 $mail_message->html = $html_message;115 116 return $this->send( $user->email, 'Reset Password', $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );117 }118 119 /**120 * Send email registration pengusul function.121 *122 * @param string $to (Required) Email Destination123 * @param string $username (Required) Username of Pengusul124 * @return Mixed125 */126 function send_email_registration_pengusul( $to, $username ) {127 if ( !$to ) return false;128 if ( !$username ) return false;129 130 $message = trim( get_option('be_notif_registration_pengusul') );131 $message = str_replace("{%username%}", $username, $message);132 133 $html_message = smit_notification_template($message);134 135 $mail_message = new stdClass();136 $mail_message->plain = $message;137 $mail_message->html = $html_message;138 139 return $this->send( $to, 'Konfirmasi Pendaftaran Pengusul', $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );140 }141 142 /**143 * Send email registration user function.144 *145 * @param string $to (Required) Email Destination146 * @param string $username (Required) Username of user147 * @return Mixed148 */149 function send_email_registration_user( $to, $username, $status ) {150 if ( !$to ) return false;151 if ( !$username ) return false;152 //if( empty($status) ) $status = 'AKTIF';153 154 $message = trim( get_option('be_notif_registration_user') );155 $message = str_replace("{%username%}", $username, $message);156 $message = str_replace("{%status%}", $status, $message);157 158 $html_message = smit_notification_template($message);159 160 $mail_message = new stdClass();161 $mail_message->plain = $message;162 $mail_message->html = $html_message;163 164 return $this->send( $to, 'Konfirmasi Pendaftaran User', $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );165 }166 167 /**168 * Send email registration juri function.169 *170 * @param string $to (Required) Email Destination171 * @param string $username (Required) Username of user172 * @param string $password (Required) Password of user173 * @return Mixed174 */175 function send_email_registration_juri( $to, $username, $password, $type ) {176 if ( !$to ) return false;177 if ( !$username ) return false;178 if ( !$password ) return false;179 if ( !$type ) return false;180 181 $message = trim( get_option('be_notif_registration_juri') );182 $message = str_replace("{%username%}", $username, $message);183 $message = str_replace("{%password%}", $password, $message);184 $message = str_replace("{%type%}", $type, $message);185 186 $html_message = smit_notification_template($message);187 188 $mail_message = new stdClass();189 $mail_message->plain = $message;190 $mail_message->html = $html_message;191 192 return $this->send( $to, 'Konfirmasi Pendaftaran', $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );193 }194 195 /**196 * Send email registration for admin function.197 *198 * @param string $to (Required) Email Destination199 * @param string $from (Required) Email Sender200 * @param string $username (Required) Username of user201 * @param string $name (Required) Name of user202 * @return Mixed203 */204 function send_email_registration_for_admin( $to, $from, $username, $name ) {205 if ( !$to ) return false;206 if ( !$from ) return false;207 if ( !$username ) return false;208 if ( !$name ) return false;209 210 $message = trim( get_option('be_notif_registration_for_admin') );211 $message = str_replace("{%username%}", $username, $message);212 $message = str_replace("{%name%}", $name, $message);213 214 $html_message = smit_notification_template_clear($message);215 216 $mail_message = new stdClass();217 $mail_message->plain = $message;218 $mail_message->html = $html_message;219 220 return $this->send( $to, 'Konfirmasi Pendaftaran User', $mail_message, $from, $name );221 }222 223 /**224 * Send email registration selection function.225 *226 * @param string $to (Required) Email Destionation227 * @param string $event_title (Required) Title of Selection228 * @return Mixed229 */230 function send_email_registration_selection( $to, $event_title ) {231 if ( !$to ) return false;232 if ( !$event_title ) return false;233 234 $message = trim( get_option('be_notif_registration_selection') );235 $message = str_replace("{%event_title%}", $event_title, $message);236 237 $html_message = smit_notification_template($message);238 239 $mail_message = new stdClass();240 $mail_message->plain = $message;241 $mail_message->html = $html_message;242 243 return $this->send( $to, 'Konfirmasi Kegiatan Seleksi ', $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );244 }245 246 /**247 * Send email rated confirmation function.248 *249 * @param string $to (Required) Email Destionation250 * @return Mixed251 */252 function send_email_rated_confirmation( $to, $step ) {253 if ( !$to ) return false;254 if ( !$step ) return false;255 256 $message = trim( get_option('be_notif_rated_selection') );257 $message = str_replace("{%step%}", 'Proses penilaian Tahap '.$step, $message);258 259 $html_message = smit_notification_template($message);260 261 $mail_message = new stdClass();262 $mail_message->plain = $message;263 $mail_message->html = $html_message;264 265 return $this->send( $to, 'Konfirmasi Penilaian', $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );266 }267 268 /**269 * Send email selection confirmation step 1 function.270 *271 * @param string $data (Required) Pra-Incubation Selection Data272 * @return Mixed273 */274 function send_email_selection_confirmation_step1( $data ) {275 if ( !$data ) return false;276 277 $message = trim( get_option('be_notif_praincubation_confirm') );278 $message = str_replace("{%event_title%}", $data->event_title, $message);279 280 $html_message = smit_notification_template($message);281 282 $mail_message = new stdClass();283 $mail_message->plain = $message;284 $mail_message->html = $html_message;285 286 return $this->send( $data->email, 'Konfirmasi Seleksi Pra-Inkubasi', $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );287 }288 289 /**290 * Send email selection confirmation step 2 function.291 *292 * @param string $data (Required) Pra-Incubation Selection Data293 * @return Mixed294 */295 function send_email_selection_confirmation_step2( $data ) {296 if ( !$data ) return false;297 298 $message = trim( get_option('be_notif_praincubation_confirm2') );299 $message = str_replace("{%event_title%}", $data->event_title, $message);300 301 $html_message = smit_notification_template($message);302 303 $mail_message = new stdClass();304 $mail_message->plain = $message;305 $mail_message->html = $html_message;306 307 return $this->send( $data->email, 'Konfirmasi Seleksi Pra-Inkubasi', $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );308 }309 310 /**311 * Send email selection not success step 1 function.312 *313 * @param array object $selection_setting (Required) Selection Setting314 * @param array object $data (Required) Pra-Incubation Selection Data315 * @return Mixed316 */317 function send_email_selection_not_success_step1 ($selection_setting, $data ) {318 if ( !$selection_setting ) return false;319 if ( !$data ) return false;320 321 $adm_date = date('j', strtotime($selection_setting->selection_date_adm_start)) . 322 ' - ' . date('j', strtotime($selection_setting->selection_date_adm_end)) . 323 ' ' . smit_indo_month( date('F', strtotime($selection_setting->selection_date_adm_end)) ) . 324 ' ' . date('Y', strtotime($selection_setting->selection_date_adm_end));325 326 $curdate = date('j') .' '. smit_indo_month( date('F') ) .' '. date('Y');327 328 $message = trim( get_option('be_notif_praincubation_not_success') );329 $message = str_replace("{%curdate%}", $curdate, $message);330 $message = str_replace("{%selection_year%}", $selection_setting->selection_year_publication, $message);331 $message = str_replace("{%user_name%}", $data->name, $message);332 $message = str_replace("{%adm_date%}", $adm_date, $message);333 $message = str_replace("{%event_title%}", $data->event_title, $message);334 335 $html_message = smit_notification_template($message);336 337 $mail_message = new stdClass();338 $mail_message->plain = $message;339 $mail_message->html = $html_message;340 341 return $this->send( $data->email, 'Konfirmasi Tidak Lolos Seleksi Tahap Awal', $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );342 }343 344 /**345 * Send email selection not success step 2 function.346 *347 * @param array object $selection_setting (Required) Selection Setting348 * @param array object $data (Required) Pra-Incubation Selection Data349 * @return Mixed350 */351 function send_email_selection_not_success_step2 ($selection_setting, $data ) {352 if ( !$selection_setting ) return false;353 if ( !$data ) return false;354 355 $adm_date = date('j', strtotime($selection_setting->selection_date_adm_start)) . 356 ' - ' . date('j', strtotime($selection_setting->selection_date_adm_end)) . 357 ' ' . smit_indo_month( date('F', strtotime($selection_setting->selection_date_adm_end)) ) . 358 ' ' . date('Y', strtotime($selection_setting->selection_date_adm_end));359 360 $curdate = date('j') .' '. smit_indo_month( date('F') ) .' '. date('Y');361 362 $message = trim( get_option('be_notif_praincubation_not_success2') );363 $message = str_replace("{%curdate%}", $curdate, $message);364 $message = str_replace("{%selection_year%}", $selection_setting->selection_year_publication, $message);365 $message = str_replace("{%user_name%}", $data->name, $message);366 $message = str_replace("{%adm_date%}", $adm_date, $message);367 368 $html_message = smit_notification_template($message);369 370 $mail_message = new stdClass();371 $mail_message->plain = $message;372 $mail_message->html = $html_message;373 374 return $this->send( $data->email, 'Konfirmasi Tidak Lolos Seleksi', $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );375 }376 377 /**378 * Send email selection success function.379 *380 * @param array object $selection_setting (Required) Selection Setting381 * @param array object $data (Required) Pra-Incubation Selection Data382 * @return Mixed383 */384 function send_email_selection_success( $selection_setting, $data ) {385 if ( !$selection_setting ) return false;386 if ( !$data ) return false;387 388 $adm_date = date('j', strtotime($selection_setting->selection_date_adm_start)) . 389 ' - ' . date('j', strtotime($selection_setting->selection_date_adm_end)) . 390 ' ' . smit_indo_month( date('F', strtotime($selection_setting->selection_date_adm_end)) ) . 391 ' ' . date('Y', strtotime($selection_setting->selection_date_adm_end));392 393 $curdate = date('j') .' '. smit_indo_month( date('F') ) .' '. date('Y');394 $inv_day = smit_indo_day( date('D', strtotime($selection_setting->selection_date_invitation_send) ) );395 $inv_date = date('j', strtotime($selection_setting->selection_date_invitation_send)) . 396 ' ' . smit_indo_month( date('F', strtotime($selection_setting->selection_date_invitation_send)) ) . 397 ' ' . date('Y', strtotime($selection_setting->selection_date_invitation_send));398 399 $message = trim( get_option('be_notif_praincubation_success') );400 $message = str_replace("{%curdate%}", $curdate, $message);401 $message = str_replace("{%selection_year%}", $selection_setting->selection_year_publication, $message);402 $message = str_replace("{%user_name%}", $data->name, $message);403 $message = str_replace("{%adm_date%}", $adm_date, $message);404 $message = str_replace("{%interview_date%}", $inv_day .', '.$inv_date, $message);405 406 407 $html_message = smit_notification_template($message);408 409 $mail_message = new stdClass();410 $mail_message->plain = $message;411 $mail_message->html = $html_message;412 413 return $this->send( $data->email, 'Konfirmasi Lolos Seleksi', $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );414 }415 416 /**417 * Send email selection accepted function.418 *419 * @param array object $selection_setting (Required) Selection Setting420 * @param array object $data (Required) Pra-Incubation Selection Data421 * @return Mixed422 */423 function send_email_selection_accepted( $selection_setting, $data ) {424 if ( !$selection_setting ) return false;425 if ( !$data ) return false;426 427 $adm_date = date('j', strtotime($selection_setting->selection_date_adm_start)) . 428 ' - ' . date('j', strtotime($selection_setting->selection_date_adm_end)) . 429 ' ' . smit_indo_month( date('F', strtotime($selection_setting->selection_date_adm_end)) ) . 430 ' ' . date('Y', strtotime($selection_setting->selection_date_adm_end));431 432 $curdate = date('j') .' '. smit_indo_month( date('F') ) .' '. date('Y');433 434 $message = trim( get_option('be_notif_praincubation_accepted') );435 $message = str_replace("{%curdate%}", $curdate, $message);436 $message = str_replace("{%selection_year%}", $selection_setting->selection_year_publication, $message);437 $message = str_replace("{%user_name%}", $data->name, $message);438 $message = str_replace("{%adm_date%}", $adm_date, $message);439 $html_message = smit_notification_template($message);440 441 $mail_message = new stdClass();442 $mail_message->plain = $message;443 $mail_message->html = $html_message;444 445 return $this->send( $data->email, 'Konfirmasi Seleksi Diterima', $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );446 }447 448 /**449 * Send email forgot password function.450 *451 * @param string $id_user (Required) ID User452 * @param string $password (Required) Password that forgot453 * @return Mixed454 */455 function send_email_contact( $email, $contact_name, $contact_email, $contact_title, $contact_desc ) {456 if ( !$contact_name ) return false;457 if ( !$contact_email ) return false;458 if ( !$contact_title ) return false;459 if ( !$contact_desc ) return false;460 461 $message = trim( get_option('be_notif_contact') );462 $message = str_replace("{%name%}", strtoupper($contact_name), $message);463 $message = str_replace("{%email%}", $contact_email, $message);464 $message = str_replace("{%title%}", $contact_title, $message);465 $message = str_replace("{%description%}", $contact_desc, $message);466 467 $html_message = smit_notification_template_clear($message);468 469 $mail_message = new stdClass();470 $mail_message->plain = $message;471 $mail_message->html = $html_message;472 473 return $this->send( $email, $contact_title, $mail_message, get_option( 'mail_sender_admin' ), 'Admin ' . get_option( 'company_name' ) );474 }475}476/*477CHANGELOG478---------479Insert new changelog at the top of the list.480-----------------------------------------------481Version YYYY/MM/DD Person Name Description482-----------------------------------------------4831.0.0 2017/01/20 Iqbal - Created this changelog484*/...

Full Screen

Full Screen

em-mailer.php

Source:em-mailer.php Github

copy

Full Screen

...15 * @param $subject16 * @param $body17 * @param $receiver18 */19 function send($subject="no title",$body="No message specified", $receiver='', $attachments = array() ) {20 //TODO add an EM_Error global object, for this sort of error reporting. (@marcus like StatusNotice)21 global $smtpsettings, $phpmailer, $cformsSettings;22 $subject = html_entity_decode(wp_kses_data($subject)); //decode entities, but run kses first just in case users use placeholders containing html23 if( is_array($receiver) ){24 $receiver_emails = array();25 foreach($receiver as $receiver_email){26 $receiver_emails[] = is_email($receiver_email);27 }28 $emails_ok = !in_array(false, $receiver_emails);29 }else{30 $emails_ok = is_email($receiver);31 }32 if( get_option('dbem_smtp_html') && get_option('dbem_smtp_html_br') ){33 $body = nl2br($body);34 }35 if ( $emails_ok && get_option('dbem_rsvp_mail_send_method') == 'wp_mail' ){36 $from = get_option('dbem_mail_sender_address');37 $headers = get_option('dbem_mail_sender_name') ? 'From: '.get_option('dbem_mail_sender_name').' <'.$from.'>':'From: '.$from;38 if( get_option('dbem_smtp_html') ){ //create filter to change content type to html in wp_mail39 add_filter('wp_mail_content_type',create_function('', 'return "text/html";'));40 }41 $send = wp_mail($receiver, $subject, $body, $headers);42 if(!$send){43 global $phpmailer;44 $this->errors[] = $phpmailer->ErrorInfo;45 }46 return $send;47 }elseif ( $emails_ok && get_option('dbem_rsvp_mail_send_method') == 'mail' ){48 if(is_array($receiver)){49 $receiver = implode(', ', $receiver);50 }51 $headers = '';52 if( get_option('dbem_smtp_html') ){53 $headers = 'MIME-Version: 1.0' . "\r\n";54 $headers .= 'Content-type: text/html; charset="UTF-8"' . "\r\n";55 }else{56 $headers = 'Content-Type: text/plain; charset="UTF-8"' . "\r\n";57 }58 $from = get_option('dbem_mail_sender_address');59 $headers .= get_option('dbem_mail_sender_name') ? 'From: '.get_option('dbem_mail_sender_name').' <'.$from.'>':'From: '.$from;60 $send = mail($receiver, $subject, $body, $headers);61 if(!$send){62 $this->errors[] = __('Could not send email.', 'dbem');63 }64 return $send;65 }elseif( $emails_ok ){66 $this->load_phpmailer();67 $mail = new EM_PHPMailer();68 //$mail->SMTPDebug = true;69 if( get_option('dbem_smtp_html') ){70 $mail->isHTML();71 }72 $mail->ClearAllRecipients();73 $mail->ClearAddresses();74 $mail->ClearAttachments();75 $mail->CharSet = 'utf-8';76 $mail->SetLanguage('en', dirname(__FILE__).'/');77 $mail->PluginDir = dirname(__FILE__).'/phpmailer/';78 $mail->Host = get_option('dbem_smtp_host');79 $mail->port = get_option('dbem_rsvp_mail_port');80 $mail->Username = get_option('dbem_smtp_username'); 81 $mail->Password = get_option('dbem_smtp_password'); 82 $mail->From = get_option('dbem_mail_sender_address'); 83 $mail->FromName = get_option('dbem_mail_sender_name'); // This is the from name in the email, you can put anything you like here84 $mail->Body = $body;85 $mail->Subject = $subject;86 //add attachments87 if( is_array($attachments) ){88 foreach($attachments as $attachment){89 $att = array('name'=> '', 'encoding' => 'base64', 'type' => 'application/octet-stream');90 if( is_array($attachment) ){91 $att = array_merge($att, $attachment);92 }else{93 $att['path'] = $attachment;94 }95 $mail->AddAttachment($att['path'], $att['name'], $att['encoding'], $att['type']);96 }97 } 98 do_action('em_mailer', $mail); //$mail will still be modified 99 if(is_array($receiver)){100 foreach($receiver as $receiver_email){101 $mail->AddAddress($receiver_email); 102 }103 }else{104 $mail->AddAddress($receiver); 105 }106 107 //Protocols108 if( get_option('dbem_rsvp_mail_send_method') == 'qmail' ){ 109 $mail->IsQmail();110 }else {111 $mail->Mailer = get_option('dbem_rsvp_mail_send_method');112 } 113 if(get_option('dbem_rsvp_mail_SMTPAuth') == '1'){114 $mail->SMTPAuth = TRUE;115 }116 $send = $mail->Send();117 if(!$send){118 $this->errors[] = $mail->ErrorInfo;119 }120 do_action('em_mailer_sent', $mail, $send); //$mail can still be modified121 return $send;122 }else{123 $this->errors[] = __('Please supply a valid email format.', 'dbem');124 return false;125 }126 }127 128 /**129 * load phpmailer classes130 */131 function load_phpmailer(){132 require_once(dirname(__FILE__) . '/phpmailer/class.phpmailer.php');133 require_once(dirname(__FILE__) . '/phpmailer/class.smtp.php');134 }135} ...

Full Screen

Full Screen

send

Using AI Code Generation

copy

Full Screen

1$mail = new Mail;2$smtp = new Smtp;3$mail->IsSMTP();4$mail->SMTPAuth = true;5$mail->SMTPSecure = "ssl";6$mail->Port = 465;7$mail->Host = "smtp.gmail.com";

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger send code on LambdaTest Cloud Grid

Execute automation tests with send on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful