function process_email_form() { global $wpdb, $post; // If User Click On Mail if (!empty($_POST['wp-email'])) { @session_start(); email_textdomain(); header('Content-Type: text/html; charset=' . get_option('blog_charset') . ''); // POST Variables $yourname = strip_tags(stripslashes(trim($_POST['yourname']))); $youremail = strip_tags(stripslashes(trim($_POST['youremail']))); $yourremarks = strip_tags(stripslashes(trim($_POST['yourremarks']))); $friendname = strip_tags(stripslashes(trim($_POST['friendname']))); $friendemail = strip_tags(stripslashes(trim($_POST['friendemail']))); $email_popup = intval($_POST['popup']); $imageverify = $_POST['imageverify']; $p = intval($_POST['p']); $page_id = intval($_POST['page_id']); // Get Post Information if ($p > 0) { $query_post = 'p=' . $p; $id = $p; } else { $query_post = 'page_id=' . $page_id; $id = $page_id; } query_posts($query_post); if (have_posts()) { while (have_posts()) { the_post(); $post_title = email_get_title(); $post_author = get_the_author(); $post_date = get_the_time(get_option('date_format') . ' (' . get_option('time_format') . ')', '', '', false); $post_category = email_category(); $post_category_alt = strip_tags($post_category); $post_excerpt = get_the_excerpt(); $post_content = email_content(); $post_content_alt = email_content_alt(); } } // Error $error = ''; $error_field = array('yourname' => $yourname, 'youremail' => $youremail, 'yourremarks' => $yourremarks, 'friendname' => $friendname, 'friendemail' => $friendemail, 'id' => $id); // Get Options $email_fields = get_option('email_fields'); $email_image_verify = intval(get_option('email_imageverify')); $email_smtp = get_option('email_smtp'); // Multiple Names/Emails $friends = array(); $friendname_count = 0; $friendemail_count = 0; $multiple_names = explode(',', $friendname); $multiple_emails = explode(',', $friendemail); $multiple_max = intval(get_option('email_multiple')); if ($multiple_max == 0) { $multiple_max = 1; } // Checking Your Name Field For Errors if (intval($email_fields['yourname']) == 1) { if (empty($yourname)) { $error .= '<br /><strong>»</strong> ' . __('Your Name is empty', 'wp-email'); } if (!is_valid_name($yourname)) { $error .= '<br /><strong>»</strong> ' . __('Your Name is invalid', 'wp-email'); } } // Checking Your E-Mail Field For Errors if (intval($email_fields['youremail']) == 1) { if (empty($youremail)) { $error .= '<br /><strong>»</strong> ' . __('Your Email is empty', 'wp-email'); } if (!is_valid_email($youremail)) { $error .= '<br /><strong>»</strong> ' . __('Your Email is invalid', 'wp-email'); } } // Checking Your Remarks Field For Errors if (intval($email_fields['yourremarks']) == 1) { if (!is_valid_remarks($yourremarks)) { $error .= '<br /><strong>»</strong> ' . __('Your Remarks is invalid', 'wp-email'); } } // Checking Friend's Name Field For Errors if (intval($email_fields['friendname']) == 1) { if (empty($friendname)) { $error .= '<br /><strong>»</strong> ' . __('Friend Name(s) is empty', 'wp-email'); } else { if ($multiple_names) { foreach ($multiple_names as $multiple_name) { $multiple_name = trim($multiple_name); if (empty($multiple_name)) { $error .= '<br /><strong>»</strong> ' . sprintf(__('Friend Name is empty: %s', 'wp-email'), $multiple_name); } elseif (!is_valid_name($multiple_name)) { $error .= '<br /><strong>»</strong> ' . sprintf(__('Friend Name is invalid: %s', 'wp-email'), $multiple_name); } else { $friends[$friendname_count]['name'] = $multiple_name; $friendname_count++; } if ($friendname_count > $multiple_max) { break; } } } } } // Checking Friend's E-Mail Field For Errors if (empty($friendemail)) { $error .= '<br /><strong>»</strong> ' . __('Friend Email(s) is empty', 'wp-email'); } else { if ($multiple_emails) { foreach ($multiple_emails as $multiple_email) { $multiple_email = trim($multiple_email); if (empty($multiple_email)) { $error .= '<br /><strong>»</strong> ' . sprintf(__('Friend Email is empty: %s', 'wp-email'), $multiple_email); } elseif (!is_valid_email($multiple_email)) { $error .= '<br /><strong>»</strong> ' . sprintf(__('Friend Email is invalid: %s', 'wp-email'), $multiple_email); } else { $friends[$friendemail_count]['email'] = $multiple_email; $friendemail_count++; } if ($friendemail_count > $multiple_max) { break; } } } } // Checking If The Fields Exceed The Size Of Maximum Entries Allowed if (sizeof($friends) > $multiple_max) { $error .= '<br /><strong>»</strong> ' . sprintf(__('Maximum %s Friend(s) allowed', 'wp-email'), $multiple_max); } if (intval($email_fields['friendname']) == 1) { if ($friendname_count != $friendemail_count) { $error .= '<br /><strong>»</strong> ' . __('Friend Name(s) count does not tally with Friend Email(s) count', 'wp-email'); } } // Check Whether We Enable Image Verification if ($email_image_verify) { $imageverify = strtoupper($imageverify); if (empty($imageverify)) { $error .= '<br /><strong>»</strong> ' . __('Image Verification is empty', 'wp-email'); } else { if ($_SESSION['email_verify'] != md5($imageverify)) { $error .= '<br /><strong>»</strong> ' . __('Image Verification failed', 'wp-email'); } } } // If There Is No Error, We Process The E-Mail if (empty($error) && not_spamming()) { // If Remarks Is Empty, Assign N/A if (empty($yourremarks)) { $yourremarks = __('N/A', 'wp-email'); } // Template For E-Mail Subject $template_email_subject = stripslashes(get_option('email_template_subject')); $template_email_subject = str_replace("%EMAIL_YOUR_NAME%", $yourname, $template_email_subject); $template_email_subject = str_replace("%EMAIL_YOUR_EMAIL%", $youremail, $template_email_subject); $template_email_subject = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_subject); $template_email_subject = str_replace("%EMAIL_POST_AUTHOR%", $post_author, $template_email_subject); $template_email_subject = str_replace("%EMAIL_POST_DATE%", $post_date, $template_email_subject); $template_email_subject = str_replace("%EMAIL_POST_CATEGORY%", $post_category_alt, $template_email_subject); $template_email_subject = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_subject); $template_email_subject = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_subject); $template_email_subject = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_subject); // Template For E-Mail Body $template_email_body = stripslashes(get_option('email_template_body')); $template_email_body = str_replace("%EMAIL_YOUR_NAME%", $yourname, $template_email_body); $template_email_body = str_replace("%EMAIL_YOUR_EMAIL%", $youremail, $template_email_body); $template_email_body = str_replace("%EMAIL_YOUR_REMARKS%", $yourremarks, $template_email_body); $template_email_body = str_replace("%EMAIL_FRIEND_NAME%", $friendname, $template_email_body); $template_email_body = str_replace("%EMAIL_FRIEND_EMAIL%", $friendemail, $template_email_body); $template_email_body = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_body); $template_email_body = str_replace("%EMAIL_POST_AUTHOR%", $post_author, $template_email_body); $template_email_body = str_replace("%EMAIL_POST_DATE%", $post_date, $template_email_body); $template_email_body = str_replace("%EMAIL_POST_CATEGORY%", $post_category, $template_email_body); $template_email_body = str_replace("%EMAIL_POST_EXCERPT%", $post_excerpt, $template_email_body); $template_email_body = str_replace("%EMAIL_POST_CONTENT%", $post_content, $template_email_body); $template_email_body = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_body); $template_email_body = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_body); $template_email_body = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_body); // Template For E-Mail Alternate Body $template_email_bodyalt = stripslashes(get_option('email_template_bodyalt')); $template_email_bodyalt = str_replace("%EMAIL_YOUR_NAME%", $yourname, $template_email_bodyalt); $template_email_bodyalt = str_replace("%EMAIL_YOUR_EMAIL%", $youremail, $template_email_bodyalt); $template_email_bodyalt = str_replace("%EMAIL_YOUR_REMARKS%", $yourremarks, $template_email_bodyalt); $template_email_bodyalt = str_replace("%EMAIL_FRIEND_NAME%", $friendname, $template_email_bodyalt); $template_email_bodyalt = str_replace("%EMAIL_FRIEND_EMAIL%", $friendemail, $template_email_bodyalt); $template_email_bodyalt = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_bodyalt); $template_email_bodyalt = str_replace("%EMAIL_POST_AUTHOR%", $post_author, $template_email_bodyalt); $template_email_bodyalt = str_replace("%EMAIL_POST_DATE%", $post_date, $template_email_bodyalt); $template_email_bodyalt = str_replace("%EMAIL_POST_CATEGORY%", $post_category_alt, $template_email_bodyalt); $template_email_bodyalt = str_replace("%EMAIL_POST_EXCERPT%", $post_excerpt, $template_email_bodyalt); $template_email_bodyalt = str_replace("%EMAIL_POST_CONTENT%", $post_content_alt, $template_email_bodyalt); $template_email_bodyalt = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_bodyalt); $template_email_bodyalt = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_bodyalt); $template_email_bodyalt = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_bodyalt); // PHP Mailer Variables if (!class_exists("phpmailer")) { require_once ABSPATH . 'wp-includes/class-phpmailer.php'; } $mail = new PHPMailer(); $mail->From = $youremail; $mail->FromName = $yourname; foreach ($friends as $friend) { $mail->AddAddress($friend['email'], $friend['name']); } $mail->Username = $email_smtp['username']; $mail->Password = $email_smtp['password']; $mail->Host = $email_smtp['server']; $mail->Mailer = get_option('email_mailer'); if ($mail->Mailer == 'smtp') { $mail->SMTPAuth = true; } $mail->ContentType = get_option('email_contenttype'); $mail->Subject = $template_email_subject; if (get_option('email_contenttype') == 'text/plain') { $mail->Body = $template_email_bodyalt; } else { $mail->Body = $template_email_body; $mail->AltBody = $template_email_bodyalt; } // Send The Mail if($mail->Send()) { if ($mail->Send()) { $email_status = __('Success', 'wp-email'); // Template For Sent Successfully $template_email_sentsuccess = stripslashes(get_option('email_template_sentsuccess')); $template_email_sentsuccess = str_replace("%EMAIL_FRIEND_NAME%", $friendname, $template_email_sentsuccess); $template_email_sentsuccess = str_replace("%EMAIL_FRIEND_EMAIL%", $friendemail, $template_email_sentsuccess); $template_email_sentsuccess = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_sentsuccess); $template_email_sentsuccess = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_sentsuccess); $template_email_sentsuccess = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_sentsuccess); $template_email_sentsuccess = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_sentsuccess); // If There Is Error Sending } else { if ($yourremarks == __('N/A', 'wp-email')) { $yourremarks = ''; } $email_status = __('Failed', 'wp-email'); // Template For Sent Failed $template_email_sentfailed = stripslashes(get_option('email_template_sentfailed')); $template_email_sentfailed = str_replace("%EMAIL_FRIEND_NAME%", $friendname, $template_email_sentfailed); $template_email_sentfailed = str_replace("%EMAIL_FRIEND_EMAIL%", $friendemail, $template_email_sentfailed); $template_email_sentfailed = str_replace("%EMAIL_ERROR_MSG%", $mail->ErrorInfo, $template_email_sentfailed); $template_email_sentfailed = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_sentfailed); $template_email_sentfailed = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_sentfailed); $template_email_sentfailed = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_sentfailed); $template_email_sentfailed = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_sentfailed); } // Logging $email_yourname = addslashes($yourname); $email_youremail = addslashes($youremail); $email_yourremarks = addslashes($yourremarks); $email_postid = intval(get_the_id()); $email_posttitle = addslashes($post_title); $email_timestamp = current_time('timestamp'); $email_ip = get_email_ipaddress(); $email_host = @gethostbyaddr($email_ip); foreach ($friends as $friend) { $email_friendname = addslashes($friend['name']); $email_friendemail = addslashes($friend['email']); $wpdb->query("INSERT INTO {$wpdb->email} VALUES (0, '{$email_yourname}', '{$email_youremail}', '{$email_yourremarks}', '{$email_friendname}', '{$email_friendemail}', {$email_postid}, '{$email_posttitle}', '{$email_timestamp}', '{$email_ip}', '{$email_host}', '{$email_status}')"); } if ($email_status == __('Success', 'wp-email')) { $output = $template_email_sentsuccess; } else { $output = $template_email_sentfailed; } echo $output; exit; // If There Are Errors } else { $error = substr($error, 21); $template_email_error = stripslashes(get_option('email_template_error')); $template_email_error = str_replace("%EMAIL_ERROR_MSG%", $error, $template_email_error); $template_email_error = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_error); $template_email_error = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_error); $template_email_error = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_error); $output = $template_email_error; if (!$email_popup) { $output .= email_form(false, false, false, false, $error_field); } else { $output .= email_form(true, false, false, false, $error_field); } echo $output; exit; } // End if(empty($error)) } // End if(!empty($_POST['wp-email'])) }
function create_email_table() { global $wpdb; email_textdomain(); if (@is_file(ABSPATH . '/wp-admin/upgrade-functions.php')) { include_once ABSPATH . '/wp-admin/upgrade-functions.php'; } elseif (@is_file(ABSPATH . '/wp-admin/includes/upgrade.php')) { include_once ABSPATH . '/wp-admin/includes/upgrade.php'; } else { die('We have problem finding your \'/wp-admin/upgrade-functions.php\' and \'/wp-admin/includes/upgrade.php\''); } $charset_collate = ''; if ($wpdb->supports_collation()) { if (!empty($wpdb->charset)) { $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $charset_collate .= " COLLATE {$wpdb->collate}"; } } // Create E-Mail Table $create_table = "CREATE TABLE {$wpdb->email} (" . "email_id int(10) NOT NULL auto_increment," . "email_yourname varchar(200) NOT NULL default ''," . "email_youremail varchar(200) NOT NULL default ''," . "email_yourremarks text NOT NULL," . "email_friendname varchar(200) NOT NULL default ''," . "email_friendemail varchar(200) NOT NULL default ''," . "email_postid int(10) NOT NULL default '0'," . "email_posttitle text NOT NULL," . "email_timestamp varchar(20) NOT NULL default ''," . "email_ip varchar(100) NOT NULL default ''," . "email_host varchar(200) NOT NULL default ''," . "email_status varchar(20) NOT NULL default ''," . "PRIMARY KEY (email_id)) {$charset_collate};"; maybe_create_table($wpdb->email, $create_table); // Add In Options (12 Records) add_option('email_smtp', array('username' => '', 'password' => '', 'server' => ''), 'Your SMTP Name, Password, Server'); add_option('email_contenttype', 'text/html', 'Your E-Mail Type'); add_option('email_mailer', 'php', 'Your Mailer Type'); add_option('email_template_subject', __('Recommended Article By %EMAIL_YOUR_NAME%: %EMAIL_POST_TITLE%', 'wp-email'), 'Template For E-Mail Subject'); add_option('email_template_body', __('<p>Hi <strong>%EMAIL_FRIEND_NAME%</strong>,<br />Your friend, <strong>%EMAIL_YOUR_NAME%</strong>, has recommended this article entitled \'<strong>%EMAIL_POST_TITLE%</strong>\' to you.</p><p><strong>Here is his/her remark:</strong><br />%EMAIL_YOUR_REMARKS%</p><p><strong>%EMAIL_POST_TITLE%</strong><br />Posted By %EMAIL_POST_AUTHOR% On %EMAIL_POST_DATE% In %EMAIL_POST_CATEGORY%</p>%EMAIL_POST_CONTENT%<p>Article taken from %EMAIL_BLOG_NAME% - <a href="%EMAIL_BLOG_URL%">%EMAIL_BLOG_URL%</a><br />URL to article: <a href="%EMAIL_PERMALINK%">%EMAIL_PERMALINK%</a></p>', 'wp-email'), 'Template For E-Mail Body'); add_option('email_template_bodyalt', __('Hi %EMAIL_FRIEND_NAME%,' . "\n" . 'Your friend, %EMAIL_YOUR_NAME%, has recommended this article entitled \'%EMAIL_POST_TITLE%\' to you.' . "\n\n" . 'Here is his/her remarks:' . "\n" . '%EMAIL_YOUR_REMARKS%' . "\n\n" . '%EMAIL_POST_TITLE%' . "\n" . 'Posted By %EMAIL_POST_AUTHOR% On %EMAIL_POST_DATE% In %EMAIL_POST_CATEGORY%' . "\n" . '%EMAIL_POST_CONTENT%' . "\n" . 'Article taken from %EMAIL_BLOG_NAME% - %EMAIL_BLOG_URL%' . "\n" . 'URL to article: %EMAIL_PERMALINK%', 'wp-email'), 'Template For E-Mail Alternate Body'); add_option('email_template_sentsuccess', '<p>' . __('Article: <strong>%EMAIL_POST_TITLE%</strong> has been sent to <strong>%EMAIL_FRIEND_NAME% (%EMAIL_FRIEND_EMAIL%)</strong></p><p>« <a href="%EMAIL_PERMALINK%">' . __('Back to %EMAIL_POST_TITLE%', 'wp-email') . '</a></p>', 'wp-email'), 'Template For E-Mail That Is Sent Successfully'); add_option('email_template_sentfailed', '<p>' . __('An error has occurred when trying to send this email: ', 'wp-email') . '<br /><strong>»</strong> %EMAIL_ERROR_MSG%</p>', 'Template For E-Mail That Failed To Sent'); add_option('email_template_error', '<p>' . __('An error has occurred: ', 'wp-email') . '<br /><strong>»</strong> %EMAIL_ERROR_MSG%</p>', 'Template For E-Mail That Has An Error'); add_option('email_interval', 10, 'The Number Of Minutes Before The User Can E-Mail The Next Article'); add_option('email_snippet', 0, 'Enable Snippet Feature For Your E-Mail?'); add_option('email_multiple', 5, 'Maximum Number Of Multiple E-Mails'); // Version 2.05 Options add_option('email_imageverify', 1, 'Enable Image Verification?'); // Version 2.10 Options $email_options = array('post_text' => __('Email This Post', 'wp-email'), 'page_text' => __('Email This Page', 'wp-email'), 'email_icon' => 'email_famfamfam.png', 'email_type' => 1, 'email_style' => 1, 'email_html' => '<a href="%EMAIL_URL%" rel="nofollow" title="%EMAIL_TEXT%">%EMAIL_TEXT%</a>'); $email_fields = array('yourname' => 1, 'youremail' => 1, 'yourremarks' => 1, 'friendname' => 1, 'friendemail' => 1); add_option('email_options', $email_options, 'Email Options'); add_option('email_fields', $email_fields, 'Email Fields'); // Version 2.11 Options add_option('email_template_title', __('E-Mail \'%EMAIL_POST_TITLE%\' To A Friend', 'wp-email'), 'Template For E-Mail Page Title'); add_option('email_template_subtitle', '<p style="text-align: center;">' . __('Email a copy of <strong>\'%EMAIL_POST_TITLE%\'</strong> to a friend', 'wp-email') . '</p>', 'Template For E-Mail Page SubTitle'); // Version 2.20 Upgrade $email_mailer = get_option('email_mailer'); if ($email_mailer == 'php') { update_option('email_mailer', 'mail'); } // Version 2.60 Upgrade delete_option('widget_email_most_emailed'); // Set 'manage_email' Capabilities To Administrator $role = get_role('administrator'); if (!$role->has_cap('manage_email')) { $role->add_cap('manage_email'); } }
function widget_email_init() { email_textdomain(); register_widget('WP_Widget_Email'); }