%PDF- %PDF-
Direktori : /var/www/pn/beta/ |
Current File : /var/www/pn/beta/smtp_wp_mailer.php |
<?php require_once("wp-load.php"); require_once('wp-includes/pluggable.php'); $site_url = 'http://said.noboxdesign.se/'; $adminEmail = 'admin@saidevelopment.org'; /****** CAPTCHA ******/ // REGISTER SITE AT https://www.google.com/recaptcha/ //$secret = ''; // Add the captcha() -function to validation /************************************* GLOBALS *************************************/ $boundary = uniqid('np'); //BOUNDARY (DON'T TOUCH) $url = get_field('mail_bas_url_till_site', 'epost'); $foretag = get_field('mail_foretagsnamn', 'epost'); $adress = get_field('mail_adress', 'epost'); $cmail = get_field('mail_kontakt_epost', 'epost'); $ctelefon = get_field('mail_kontakt_telefon', 'epost'); $cright = get_field('mail_copyright_text', 'epost'); $color = get_field('mail_huvudfarg', 'epost'); $tlogo = get_field('mail_logotyp_sidhuvud', 'epost'); $blogo = get_field('mail_logotyp_sidfot', 'epost'); $facebook = get_field('mail_facebook_url', 'epost'); $instagram = get_field('mail_instagram_url', 'epost'); $linkedin = get_field('mail_linkedin_url', 'epost'); $twitter = get_field('mail_twitter_url', 'epost'); /************************************* CONTACT FORM *************************************/ /*----------------------------------- FOUND ON PAGES: ----------------------------------*/ /* /contact-us/ */ if(isset($_GET['contactform'])){ if ( stristr($_SERVER['HTTP_REFERER'],$site_url) && smtp_validate($_POST['name']) && smtp_validate($_POST['email'],'email') && smtp_validate($_POST['message'])) { $form_id = 'Contact form'; $name = strip_tags(htmlspecialchars($_POST['name'])); $email = strip_tags(htmlspecialchars($_POST['email'])); $msg = strip_tags(htmlspecialchars(nl2br($_POST['message']))); //TITLE IN MAIL $sub = "Contacted from Contact page"; //SHORT EXCERPT VIEWED IN EG. GMAIL $excerpt = "A user has used the form on the contact page"; //MAIN MESSAGE IN MAIL $message = "<h1 style='font-size:24px;line-height:30px;margin:0 0 0;'>{$sub}</h1> <h2 style='font-size:18px;font-weight:400;line-height:30px;margin:0 0 20px;color:{$color};'>{$excerpt}</h2> <strong>User information</strong><br/> Name: {$name}<br /> Email: <a href='mailto:{$email}' style='color:{$color};'>{$email}</a><br /> <br /> <strong>Message</strong><br/> {$msg}"; $from = 'no-reply@saiddevelopment.org'; $headers = array('Content-Type: text/html; charset=UTF-8'); wp_mail($adminEmail, $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers); //wp_mail('kim@noboxsolutions.se', $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers); header("Location: {$site_url}contact-us/?contactform_sent"); exit; }else{ header("Location: {$site_url}contact-us/?contactform_error"); exit; } } /************************************* REGISTER FORM *************************************/ /*----------------------------------- FOUND ON PAGES: -----------------------------------*/ /* /user-registration */ if(isset($_GET['registrationform'])){ if ( stristr($_SERVER['HTTP_REFERER'],$site_url) && smtp_validate($_POST['org']) && smtp_validate($_POST['firstname']) && smtp_validate($_POST['lastname']) && smtp_validate($_POST['email'],'email') /*&& captcha()*/ ) { $org = $_POST['org']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $pw = $_POST['password']; $position = $_POST['position']; $department = $_POST['department']; $phone = $_POST['telephone']; /*---- CREATE THE USER -----*/ $uNameFirst = strtolower($firstname); $uNameLast = strtolower($lastname); $userdata = array( //'user_login' => $uNameFirst.'_'.$uNameLast, // ex forstname_lastname 'user_login' => $email, // ex forstname_lastname 'user_pass' => $pw, 'user_url' => '', 'user_email' => $email, 'display_name' => $firstname.' '.$lastname, 'first_name' => $firstname, 'last_name' => $lastname, 'role' => 'project_manager' ); $create_user = wp_insert_user($userdata); add_user_meta($create_user, 'organization', $org); add_user_meta($create_user, 'position', $position); add_user_meta($create_user, 'department', $department); add_user_meta($create_user, 'telephone', $phone); //SET AN ID FOR FORM $form_id = 'Register form'; //TITLE IN MAIL $sub = "Registration Request"; //SHORT EXCERPT VIEWED IN EG. GMAIL $excerpt = 'Request for User Registration'; $editUserLink = "{$site_url}wp-admin/user-edit.php?user_id={$create_user}&wp_http_referer=%2Fwp-admin%2Fusers.php"; //MAIN MESSAGE IN MAIL $message = "<h1 style='font-size:24px;line-height:30px;margin:0 0 0;'>{$sub}</h1> <h2 style='font-size:18px;font-weight:400;line-height:30px;margin:0 0 20px;color:{$color};'>{$excerpt}</h2> A user has filled out the registration form and is awaiting activation.<br /> <a href='{$editUserLink}' style='color:{$color};'>Review the user</a>"; $from = 'no-reply@saiddevelopment.org'; $headers = array('Content-Type: text/html; charset=UTF-8'); wp_mail($adminEmail, $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers); //wp_mail('kim@noboxsolutions.se', $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers); header("Location: {$site_url}user-registration/?registration_sent"); exit; }else{ header("Location: {$site_url}user-registration/?registration_failed"); exit; } } /************************************* USER ACTIVATED *************************************/ if(isset($_GET['user_activated']) && isset($_GET['user']) && isset($_GET['key'])){ if (stristr($_SERVER['HTTP_REFERER'],$site_url)){ $ID = $_GET['user']; $KEY = $_GET['key']; $user = get_userdata($ID); $userEmail = $user->user_email; $deCrypt = md5($userEmail); if($KEY == $deCrypt){ $form_id = 'User Activated'; //TITLE IN MAIL $sub = "SAI Capacity Development Database"; //SHORT EXCERPT VIEWED IN EG. GMAIL $excerpt = 'Welcome as a new user of the SAI Capacity Development Database'; //MAIN MESSAGE IN MAIL $message = "<h1 style='font-size:24px;line-height:30px;margin:0 0 0;'>{$sub}</h1> <h2 style='font-size:18px;font-weight:400;line-height:30px;margin:0 0 20px;color:{$color};'>{$excerpt}</h2> Your user name is: {$userEmail}<br /> Your password is: <i>-same as entered on registration-</i><br /> <br /> As a user you will be able to enter information on capacity building projects into the database. Please consult the User Guide for more information.<br /> Log into the database here: <a href='{$site_url}' style='color:{$color};'>{$site_url}</a><br /> <br /> Regards<br /> INTOSAI Donor Cooperation<br /> <a href='mailto:admin@saidevelopment.org' style='color:{$color};'>admin@saidevelopment.org</a>"; $from = 'no-reply@saiddevelopment.org'; $headers = array('Content-Type: text/html; charset=UTF-8'); wp_mail($userEmail, $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers); //wp_mail('kim@noboxsolutions.se', $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers); header("Location: {$site_url}wp-admin/users.php?user_activated"); exit; }else{ header("Location: {$site_url}wp-admin/users.php?user_activation_failed"); exit; } }else{ header("Location: {$site_url}wp-admin/users.php?user_activation_failed"); exit; } } /************************************* USER DEACTIVATED *************************************/ if(isset($_GET['user_deactivated']) && isset($_GET['user']) && isset($_GET['key'])){ if (stristr($_SERVER['HTTP_REFERER'],$site_url)){ $ID = $_GET['user']; $KEY = $_GET['key']; $user = get_userdata($ID); $userEmail = $user->user_email; $deCrypt = md5($userEmail); if($KEY == $deCrypt){ $form_id = 'User Deactivated'; //TITLE IN MAIL $sub = "SAI Capacity Development Database"; //SHORT EXCERPT VIEWED IN EG. GMAIL $excerpt = 'Your user has been deactivated'; //MAIN MESSAGE IN MAIL $message = "<h1 style='font-size:24px;line-height:30px;margin:0 0 0;'>".$sub."</h1> <h2 style='font-size:18px;font-weight:400;line-height:30px;margin:0 0 20px;color:".$color.";'>".$excerpt."</h2> Your user on INTOSAI-Donor Cooperation has been Deactivated.<br /> If you believe this was a misstake please contact us using the information below.<br /> <br /> Regards<br /> INTOSAI Donor Cooperation<br /> <a href='mailto:admin@saidevelopment.org' style='color:{$color};'>admin@saidevelopment.org</a>"; $from = 'no-reply@saiddevelopment.org'; $headers = array('Content-Type: text/html; charset=UTF-8'); wp_mail($userEmail, $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers); //wp_mail('kim@noboxsolutions.se', $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers); header("Location: {$site_url}wp-admin/users.php?user_deactivated"); exit; }else{ header("Location: {$site_url}wp-admin/users.php?user_deactivation_failed"); exit; } }else{ header("Location: {$site_url}wp-admin/users.php?user_deactivation_failed"); exit; } } /************************************* SUGGEST CHANGES TO SAI *************************************/ /*----------------------------------- FOUND ON PAGES: -----------------------------------*/ /* /project-database/ */ if(isset($_GET['suggest-changes'])){ if ( stristr($_SERVER['HTTP_REFERER'],$site_url) && smtp_validate($_POST['saiToChange']) && smtp_validate($_POST['name']) && smtp_validate($_POST['email'],'email') && smtp_validate($_POST['changes'])) { $form_id = 'Change SAI'; $sai = strip_tags(htmlspecialchars($_POST['saiToChange'])); $name = strip_tags(htmlspecialchars($_POST['name'])); $email = strip_tags(htmlspecialchars($_POST['email'])); $changes = strip_tags(htmlspecialchars(nl2br($_POST['changes']))); $file = $_FILES["file"]; // Kollar om filen är tom eller ej if($file['size'] != 0) { $uploadOk = 1; $targetFolder = "/home/said/public_html/64801_wp-uploads/sai_attachments/"; //Ändrar namn på fil $allowedTypes = array('.pdf', '.docx', '.doc', '.xlsx', '.xls', '.ppt', '.pptx', '.odt'); $filename = basename($_FILES['file']['name']); $fileType = pathinfo($filename,PATHINFO_EXTENSION); $sanitizedFilename = str_replace($allowedTypes, '', $filename); $new = $sanitizedFilename.'_'. rand(100, 10000).'.'.$fileType; $filename = $targetFolder . $new; // Kontrollera filtyper if($fileType != "pdf" && $fileType != "doc" && $fileType != "docx" && $fileType != "xls" && $fileType != "xlsx" && $fileType != "ppt" && $fileType != "pptx" && $fileType != "odt") { $uploadOk = 0; } if ($uploadOk == 0) { $attachment = ''; } else { if (move_uploaded_file($_FILES["file"]["tmp_name"], $filename)) { $attachment = $filename; $attachment = array($attachment); } } } //var_dump($attachment);die(); if($attachment != ''){ $attachExists = "<br /><br /><i>The user has attached a file.</i>"; } //TITLE IN MAIL $sub = "Change request for SAI"; //SHORT EXCERPT VIEWED IN EG. GMAIL $excerpt = "A user has requested changes to be made for {$sai}"; //MAIN MESSAGE IN MAIL $message = "<h1 style='font-size:24px;line-height:30px;margin:0 0 0;'>{$sub}</h1> <h2 style='font-size:18px;font-weight:400;line-height:30px;margin:0 0 20px;color:{$color};'>{$excerpt}</h2> A user by the name of <b>{$name}</b> (<i><a href='{$email}' style='color:{$color};'>{$email}</a></i>), has requested changes to be made in the description of the SAI <b>{$sai}</b>.<br /> <br /> <b>The user suggests the following changes:</b><br/ > {$changes} {$attachExists}"; $from = 'no-reply@saiddevelopment.org'; $headers = array('Content-Type: text/html; charset=UTF-8'); wp_mail($adminEmail, $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers, $attachment); //wp_mail('kim@noboxsolutions.se', $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers, $attachment); header("Location: {$site_url}project-database/?suggestion_sent"); exit; }else{ header("Location: {$site_url}project-database/?suggestion_failed"); exit; } } /************************************* PROJECT REVISION MERGE *************************************/ /*---------------------------------------- FOUND ON PAGES: ---------------------------------------*/ if(isset($_GET['revision_merged'])){ $form_id = 'Project merge'; $revisionMergedTo = $_GET['revision_merged']; $sendOnce = $_GET['send']; $projectTitle = get_the_title($revisionMergedTo); $authorID = get_post_field('post_author', $revisionMergedTo); $authorEmail = get_the_author_meta('user_email', $authorID); //TITLE IN MAIL $sub = "Project changes published"; //SHORT EXCERPT VIEWED IN EG. GMAIL $excerpt = "The changes to your project has been approved"; //MAIN MESSAGE IN MAIL $message = "<h1 style='font-size:24px;line-height:30px;margin:0 0 0;'>{$sub}</h1> <h2 style='font-size:18px;font-weight:400;line-height:30px;margin:0 0 20px;color:{$color};'>{$excerpt}</h2> Changes to the project named <strong>{$projectTitle}</strong> has been published."; $from = 'no-reply@saiddevelopment.org'; $headers = array('Content-Type: text/html; charset=UTF-8'); if($sendOnce == '1'){ wp_mail($authorEmail, $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers); //wp_mail('kim@noboxsolutions.se', $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers); $sendOnce = '0'; } header("Location: {$site_url}wp-admin/post.php?post={$revisionMergedTo}&action=edit&project_updated"); exit; } /************************************* PROJECT PUBLISHED *************************************/ /*-------------------------------------- FOUND ON PAGES: ------------------------------------*/ if(isset($_GET['project_published'])){ $form_id = 'Project published'; $publishedProject = $_GET['project_published']; $projectTitle = get_the_title($publishedProject); $authorID = get_post_field('post_author', $publishedProject); $authorEmail = get_the_author_meta('user_email', $authorID); //TITLE IN MAIL $sub = "Project published"; //SHORT EXCERPT VIEWED IN EG. GMAIL $excerpt = "Your project has been approved and published"; //MAIN MESSAGE IN MAIL $message = "<h1 style='font-size:24px;line-height:30px;margin:0 0 0;'>{$sub}</h1> <h2 style='font-size:18px;font-weight:400;line-height:30px;margin:0 0 20px;color:{$color};'>{$excerpt}</h2> Your project with the name <strong>{$projectTitle}</strong> has been approved and published.<br /> It is now visible in the <a href='{$site_url}project-database/' style='color:{$color};'>SAI Capacity Database."; $from = 'no-reply@saiddevelopment.org'; $headers = array('Content-Type: text/html; charset=UTF-8'); wp_mail($authorEmail, $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers); //wp_mail('kim@noboxsolutions.se', $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers); header("Location: {$site_url}wp-admin/edit.php?post_type=project&project_published"); exit; } // /************************************* FUNTIONER *************************************/ function captcha(){ global $secret; $verify_url = 'https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST["g-recaptcha-response"].'&remoteip='.$_SERVER['REMOTE_ADDR']; $json = file_get_contents($verify_url); $obj = json_decode($json); if($obj->success){ return true; }else{ return false; } } function smtp_validate($validate,$field_type = null){ if( !empty($validate) && searchStringForSpam($validate) && field_type_validate($validate,$field_type) ){ return true; }else{ return false; } } function searchStringForSpam($validate){ $strings_to_search = array('href=', '[/url'); foreach ($strings_to_search as $needle) { if( stristr($validate, $needle) ){ $spam = true; return false; } } if($spam){ return false; }else{ return true; } } function field_type_validate($validate,$field_type){ if($field_type === 'email'){ if (!filter_var($validate, FILTER_VALIDATE_EMAIL)) { return false; }else{ return true; } }else{ return true; } } function smtp_sub($sub){ $subject = mb_encode_mimeheader(utf8_decode($sub), 'UTF-8', 'B'); return $subject; } function smtp_params($from){ $params = "-f ".$from; return $params; } function smtp_mail($sub,$message,$excerpt,$page_sender,$form_id) { global $url; global $foretag; global $color; global $tlogo; global $blogo; global $cmail; global $ctelefon; global $adress; global $facebook; global $instagram; global $linkedin; global $twitter; if(!empty($facebook)){ $facebook = '<a href="'.$facebook.'" target="_blank" style="display:block;float:left;margin-right:5px;border:1px solid #fff;width:30px;height:30px;text-align:center;color:#fff;text-decoration:none;background:url('.$url.'/mail_social_sprite.png) top 0px left 0px"></a>'; } if(!empty($instagram)){ $instagram = '<a href="'.$facebook.'" target="_blank" style="display:block;float:left;margin-right:5px;border:1px solid #fff;width:30px;height:30px;text-align:center;color:#fff;text-decoration:none;background:url('.$url.'/mail_social_sprite.png) top 0px left -30px;"></a>'; } if(!empty($linkedin)){ $linkedin ='<a href="'.$linkedin.'" target="_blank" style="display:block;float:left;margin-right:5px;border:1px solid #fff;width:30px;height:30px;text-align:center;color:#fff;text-decoration:none;background:url('.$url.'/mail_social_sprite.png) top 0px left -60px;"></a>'; } if(!empty($twitter)){ $twitter ='<a href="'.$twitter.'" target="_blank" style="display:block;float:left;margin-right:5px;border:1px solid #fff;width:30px;height:30px;text-align:center;color:#fff;text-decoration:none;background:url(url('.$url.'/mail_social_sprite.png) top 0px left -90px;"></a>'; } $html_mail .= '<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <!-- utf-8 works for most cases --> <meta name="viewport" content="width=device-width"> <!-- Forcing initial-scale shouldnt be necessary --> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- Use the latest (edge) version of IE rendering engine --> <title>'.$sub.'</title> <!-- the <title> tag shows on email notifications on Android 4.4. --> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#f4f4f4" style="margin:20px 0; padding:0; -webkit-text-size-adjust:none; -ms-text-size-adjust:none;"> <table cellpadding="0" cellspacing="0" border="0" height="100%" width="100%" bgcolor="#f4f4f4" id="bodyTable" style="border-collapse: collapse;table-layout: fixed;margin:0 auto;"><tr><td> <!-- Hidden Preheader Text : BEGIN --> <div style="display:none; visibility:hidden; opacity:0; color:transparent; height:0; width:0;line-height:0; overflow:hidden;mso-hide: all;"> '.$excerpt.' </div> <!-- Hidden Preheader Text : END --> <!-- Outlook and Lotus Notes dont support max-width but are always on desktop, so we can enforce a wide, fixed width view. --> <!-- Beginning of Outlook-specific wrapper : BEGIN --> <!--[if (gte mso 9)|(IE)]> <table width="600" align="center" cellpadding="0" cellspacing="0" border="0"> <tr> <td> <![endif]--> <!-- Beginning of Outlook-specific wrapper : END --> <!-- Email wrapper : BEGIN --> <table border="0" width="100%" cellpadding="0" cellspacing="0" align="center" style="max-width: 600px;margin: auto;" class="email-container"> <tr> <td style="text-align:left;padding:20px 40px;font-family:sans-serif;font-size:16px;line-height:24px;color:#fff;background:'.$color.';"> <img src="'.$tlogo.'" /> </td> </tr> <tr> <td> <table border="0" width="100%" cellpadding="0" cellspacing="0" bgcolor="#ffffff"> <!-- Full Width, Fluid Column : BEGIN --> <tr> <td style="padding: 40px; font-family: sans-serif; font-size: 16px; line-height: 24px; color: #666666;"> '.$message.' </td> </tr> </td> </tr> <!-- Full Width, Fluid Column : END --> </table> </td> </tr> <tr> <td style="text-align:center;padding:20px 40px;font-family:sans-serif;font-size:12px;line-height:18px;color:#fff;background:#222;border-top:4px solid '.$color.';"> <table border="0" width="100%" cellpadding="0" cellspacing="0" style="margin-bottom:20px;"> <tr> <td style="width:50%;padding:0 10px 0 0;text-align:left;vertical-align:top;"> <div style="display:block;width:100%;margin-bottom:15px;"> <img src="'.$blogo.'" style="width:150px;height:auto;" /><br /> </div> '.$facebook.' '.$instagram.' '.$linkedin.' '.$twitter.' </td> <td style="width:50%;padding:0 0 0 10px;text-align:left;color:#fff;"> <strong>'.$foretag.'</strong><br /> '.$adress.'<br /> <a href="mailto:'.$cmail.'" style="display:block;margin-top:5px;color:#ffffff;">'.$cmail.'</a> <a href="tel:'.$ctelefon.'" style="display:block;margin-top:5px;color:#ffffff;">'.$ctelefon.'</a> </td> </tr> </table> </td> </tr> <tr> <td style="text-align:center;padding:10px 0;font-family:sans-serif;font-size:12px;line-height:18px;color:#444;background:transparent;"> '.$cright.' </td> </tr> </table> <!-- Email wrapper : END --> <!-- End of Outlook-specific wrapper : BEGIN --> <!--[if (gte mso 9)|(IE)]> </td> </tr> </table> <![endif]--> <!-- End of Outlook-specific wrapper : END --> </td></tr></table> </body> </html>'; return $html_mail; } ?>