Advertisement
dvLden_

Sample PHPMailer

Jul 4th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. // Use composer to autoload PHPMailer or else require their integrated autoloader...
  2.  
  3. $data = (object) [
  4.     'username' => 'your.email@gmail.com',
  5.     'password' => 'generated_app_password'
  6. ];
  7.  
  8. $phpmailer = samplePHPMailer($data);
  9.  
  10. function samplePHPMailer ($credentials) {
  11.     $mailer = new PHPMailer;
  12.     $mailer->isSMTP();
  13.     $mailer->SMTPDebug = 2;
  14.     $mailer->Debugoutput = 'html';
  15.     $mailer->SMTPOptions = [
  16.         'ssl' => [
  17.             'verify_peer'       => false,
  18.             'verify_peer_name'  => false,
  19.             'allow_self_signed' => true
  20.         ]
  21.     ];
  22.     $mailer->Host = 'smtp.gmail.com';
  23.     $mailer->Port = 587;
  24.     $mailer->SMTPSecure = 'tls';
  25.     $mailer->SMTPAuth = true;
  26.     $mailer->Username = $credentials->username;
  27.     $mailer->Password = $credentials->password;
  28.     $mailer->setFrom($credentials->username, 'Inspot Gaming');
  29.     $mailer->addReplyTo($credentials->username, 'Inspot Gaming');
  30.     $mailer->addAddress('n.dvLden@gmail.com'); // send to whom...
  31.     $mailer->Subject = 'Sample Test';
  32.     $mailer->Body = 'This is sample non-HTML test...';
  33.     $mailer->AltBody = 'Some alt body goes here...';
  34.  
  35.     return !$mailer->send()
  36.         ? false
  37.         : true;  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement