Guest User

Untitled

a guest
Jul 3rd, 2018
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. <?php include("../../../wp-blog-header.php");
  2.  
  3.  
  4. /**AZIONE DI INSERIMENTO DALLA FORM DEL SITO**/
  5.  
  6. function AggiungiEmail() {
  7. global $_POST;
  8. global $wpdb;
  9. require_once('class.phpmailer.php');
  10. include_once('class.smtp.php');
  11.  
  12. $table_email = $wpdb->prefix . "nl_email";
  13.  
  14. //messaggio di successo
  15. $successo="'<div id=\"message\" class=\"updated fade\"><p><strong>".__('Thank you for subscribe. You will receive an email shortly with confirmation link!', 'sendit')."</p></div>'";
  16. //messaggio di errore
  17. $errore="'<div id=\"message\" class=\"updated fade\"><p><strong>".__('not valid email address', 'sendit')."</strong></p></div>'";
  18.  
  19. if(isset($_POST['email_add'])):
  20.  
  21. if (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email_add'])) :
  22.  
  23. die( "document.getElementById('dati').innerHTML = $errore;" );
  24.  
  25. else :
  26.  
  27.  
  28. $user_count = $wpdb->get_var("SELECT COUNT(*) FROM $table_email where email ='$_POST[email_add]' and id_lista = '$_POST[lista]';");
  29.  
  30. if($user_count>0) :
  31. $errore_presente = "'<div class=\"error\">".__('email address already present', 'sendit')."</div>'";
  32. die( "document.getElementById('dati').innerHTML = $errore_presente;" );
  33. else :
  34.  
  35. //genero stringa univoca x conferme sicure
  36. $code = md5(uniqid(rand(), true));
  37.  
  38. $wpdb->query("INSERT INTO $table_email (email, id_lista, magic_string, accepted) VALUES ('$_POST[email_add]', '$_POST[lista]','$code','n')");
  39.  
  40. /*qui mando email*/
  41.  
  42. $table_liste = $wpdb->prefix . "nl_liste";
  43.  
  44. $templaterow=$wpdb->get_row("SELECT * from $table_liste where id_lista = '$_POST[lista]' ");
  45. //costruisco il messaggio come oggetto composto da $gheader $messagio $ footer
  46.  
  47. //utile anzi fondamentale
  48. $plugindir = "sendit/";
  49. $sendit_root = get_option('siteurl') . '/wp-content/plugins/'.$plugindir;
  50. $siteurl = get_option('siteurl');
  51.  
  52. $header= $templaterow->header;
  53. //$messaggio= $templaterow->welcome;
  54. $welcome = __('Welcome to newsletter by: ', 'sendit').get_bloginfo('blog_name');
  55. $messaggio= "<h3>".$welcome."</h3>";
  56. $messaggio.=__('To confirm your subscription please follow this link', 'sendit').":<br />
  57. <a href=\"".$sendit_root."confirmation.php?action=confirm&c=".$code."\">".__('Confirm here', 'sendit')."</a>";
  58. $footer= $templaterow->footer;
  59.  
  60. $content_send = $header.$messaggio.$footer;
  61. #### Creo object PHPMailer e imposto le COSTANTI SMTP PHPMAILER
  62. $mail = new PHPMailer();
  63.  
  64. if(get_option('sendit_smtp_host')!='') :
  65. //print_r($mail);
  66. $mail->IsSMTP(); // telling the class to use SMTP
  67.  
  68.  
  69. $mail->Host = get_option('sendit_smtp_host'); // Host
  70. $mail->Hostname = get_option('sendit_smtp_hostname');// SMTP server hostname
  71. $mail->Port = get_option('sendit_smtp_port');// set the SMTP port
  72.  
  73. if(get_option('sendit_smtp_auth')=='1'):
  74. $mail->SMTPAuth = true; // turn on SMTP authentication
  75. $mail->Username = get_option('sendit_smtp_username'); // SMTP username
  76. $mail->Password = get_option('sendit_smtp_password'); // SMTP password
  77. else :
  78. $mail->SMTPAuth = false;// disable SMTP authentication
  79. endif;
  80. endif;
  81.  
  82. $mail->SetFrom($templaterow->email_lista);
  83. //$mail->AddReplyTo('pinobulini@gmail.com');
  84. $mail->Subject = $welcome;
  85. $mail->AltBody = " To view the message, please use an HTML compatible email viewer!";
  86. // optional, comment out and test
  87. $mail->MsgHTML($content_send);
  88.  
  89. $admin_mail_message = __('New subscriber for your newsletter: ', 'sendit'). get_bloginfo('blog_name');
  90.  
  91. $mail->AddAddress($_POST['email_add']);
  92. if($mail->Send()) :
  93. //echo $successo ;
  94. die( "document.getElementById('dati').innerHTML = $successo;" );
  95. else :
  96.  
  97. //echo $errore;
  98. die( "document.getElementById('dati').innerHTML = $errore;" );
  99. endif;
  100. //notifica a admin
  101. $mail->ClearAddresses();
  102. $mail->AddAddress($templaterow->email_lista);
  103. $mail->Subject = $admin_mail_message;
  104. $mail->AltBody = __('New subscriber for your newsletter: ', 'sendit').get_bloginfo('blog_name');
  105. // optional, comment out and test
  106. $mail->MsgHTML($_POST['email_add'].__(' subscribe to your mailing list: ').get_bloginfo('url'));
  107. $mail->Send();
  108. endif;
  109.  
  110. endif;
  111.  
  112. endif;
  113.  
  114.  
  115. }
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. AggiungiEmail();
  123.  
  124.  
  125.  
  126. ?>
Add Comment
Please, Sign In to add comment