Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. function deliver_mail() {    
  2.              //name of button
  3.         require_once "C:/xampp/htdocs/WP/wp-includes/class-phpmailer.php";
  4.      
  5.         // sanitize form values
  6.         $name    = sanitize_text_field( $_POST["name"] );
  7.         $email   = sanitize_email( $_POST["email"] );
  8.         $subject = sanitize_text_field( $_POST["subject"] );
  9.         $message = esc_textarea( $_POST["message"] );
  10.         // get the blog administrator's email address
  11.         //$d = ($_POST["hidden"]);
  12.         $headers = "From: $name <$email>" . "\r\n";
  13.  
  14.         // Localhost
  15.         $mail = new PHPMailer(true);
  16.         $mail->IsSMTP(); // telling the class to use SMTP
  17.         $mail->CharSet = 'UTF-8';
  18.        
  19.         $mail->SMTPDebug = 0;                     // enables SMTP debug information (for testing)
  20.         $mail->SMTPAuth = true;                  // enable SMTP authentication
  21.         $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
  22.         $mail->Host = "mail.gmx.com";      // sets GMX as the SMTP server for example: mail.gmx.com
  23.         $mail->Port = 465;                 // set the SMTP port for the GMX server
  24.        
  25.        
  26.         $mail->Username = $email;
  27.         $mail->Password = 'pass';
  28.        
  29.         $mail->SetFrom($email, $name);
  30.         $mail->AddAddress($instance['email']);
  31.         //Here has to be accessed $instance['email'] variable from the form() function;
  32.        
  33.         $mail->Subject = $subject;
  34.         $mail->MsgHTML($message);
  35.        
  36.         $headers .= "Content-Type: text/html; charset=utf-8";
  37.         $headers .= "Content-Transfer-Encoding: 8bit";
  38.        
  39.         try {
  40.             $mail->send();
  41.             $msg = "An email has been sent for verfication.";
  42.             $msgType = "success";
  43.            
  44.            
  45.         } catch (Exception $ex) {
  46.             $msg = $ex->getMessage();
  47.             $msgType = "warning";
  48.            
  49.         }
  50.        
  51.         die();
  52.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement