Advertisement
TeRackSito

php-mailer example using app password

Nov 28th, 2024
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. <?php
  2. use PHPMailer\PHPMailer\PHPMailer;
  3. use PHPMailer\PHPMailer\SMTP;
  4. use PHPMailer\PHPMailer\Exception;
  5.  
  6. require_once '../vendor/autoload.php';
  7.  
  8. $mail = new PHPMailer(true);
  9.  
  10. //Configure SMTP
  11. $mail->isSMTP();
  12. $mail->Host = 'smtp.gmail.com';
  13. $mail->SMTPAuth = true;
  14. $mail->Username = 'acho.chuchi.8@gmail.com';
  15. $mail->Password = 'jgyb jkzr vizi vmsn';
  16. $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
  17. $mail->Port = 587;
  18.  
  19. //sender information
  20. $mail->setFrom('acho.chuchi.8@gmail.com', 'TeRackSito');
  21.  
  22. //receiver email address and name
  23. $mail->addAddress('etiennesmtnf@gmail.com', 'Estienne');
  24.  
  25. // Add cc or bcc  
  26. // $mail->addCC('email@mail.com');  
  27. // $mail->addBCC('user@mail.com');  
  28.  
  29.  
  30. $mail->isHTML(false);
  31.  
  32. $mail->Subject = 'Estienne';
  33. $mail->Body    = "Hello Estienne,\n\nThis is a test email.\n\nGoodbye,\nTeRackSito";
  34.  
  35. // $mail->addAttachment('/path/to/file1.pdf', 'CustomName1.pdf'); // Attachment 1
  36.  
  37. // Attempt to send the email
  38. if (!$mail->send()) {
  39.     echo 'Email not sent. An error was encountered: ' . $mail->ErrorInfo;
  40. } else {
  41.     echo 'Message has been sent.';
  42. }
  43.  
  44. $mail->smtpClose();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement