Advertisement
Guest User

MailMethod

a guest
Feb 5th, 2018
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. Runs on a local server
  5. knowledge base
  6.  
  7. https://github.com/PHPMailer/PHPMailer
  8.  
  9. https://stackoverflow.com/questions/21545448/phpmailer-sent-message-but-returned-client-server-dialog-to-browser
  10.  
  11. */
  12.  
  13. require_once('PHPMailer/PHPMailerAutoload.php');
  14. //makes use of php mailer library
  15.  
  16. define ('gmailUserame','yours');
  17. define ('gmailPassword','yours');
  18.  
  19. //uses gmail as mail server hence you need to provide your credentials
  20.  
  21. global $error;
  22.  
  23. function smtpmailer($to, $from, $from_name, $subject, $body) {
  24.    
  25.     $mail = new PHPMailer();  // create a new object
  26.     $mail->IsSMTP(); // enable SMTP
  27.     $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
  28.     $mail->SMTPAuth = true;  // authentication enabled
  29.     $mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
  30.     $mail->SMTPAutoTLS = false;
  31.     $mail->Host = 'smtp.gmail.com';
  32.     $mail->Port = 587;
  33. /*
  34.   this lines of code is unnecessary if you are running on a secure server
  35. */
  36.     $mail->SMTPOptions = array(
  37.     'ssl' => array(
  38.         'verify_peer' => false,
  39.         'verify_peer_name' => false,
  40.         'allow_self_signed' => true
  41.     )
  42.  
  43.     /*
  44.  
  45.      unnecessary code on secure server ends here
  46.  
  47.     */
  48. );
  49.  
  50.     $mail->Username = gmailUserame;  
  51.     $mail->Password = gmailPassword;          
  52.     $mail->SetFrom($from, $from_name);
  53.     $mail->Subject = $subject;
  54.     $mail->Body = $body;
  55.     $mail->AddAddress($to);
  56.     if(!$mail->Send()) {
  57.         $error = 'Mail error: '.$mail->ErrorInfo;
  58.         return false;
  59.     } else {
  60.         $error = 'Message sent!';
  61.         return true;
  62.     }
  63. }
  64.  
  65. $from = $_GET['email'];
  66. $subject = $_GET['subject'];
  67. $body = $_GET['body'];
  68.  
  69.  
  70.  
  71. //Call method ($to, $from, $from_name, $subject, $body)
  72.  smtpmailer('onyemenamndu@gmail.com',$from,'Ndubuisi',$subject,$body);
  73.  //use whatever mail you like
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement