Advertisement
nstruth2

PHPMailer Not Working

Jul 29th, 2023
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1. <?php
  2. // Import PHPMailer classes into the global namespace
  3. use PHPMailer\PHPMailer\PHPMailer;
  4. use PHPMailer\PHPMailer\Exception;
  5.  
  6. // Include PHPMailer library files
  7. require 'vendor/autoload.php';
  8.  
  9. // Create an instance of PHPMailer class
  10. $mail = new PHPMailer(true);
  11. // SMTP configuration
  12. $mail->isSMTP();
  13. $mail->Host     = 'smtp.mailgun.org';
  14. $mail->SMTPAuth = true;
  15. $mail->Username = '[email protected]';
  16. $mail->Password = '1645e3da6b516b3220e6097d9432d850-73f745ed-8e219784';
  17. $mail->SMTPSecure = 'tls';
  18. $mail->Port     = 587;
  19.  
  20. // Sender info
  21. $mail->setFrom('[email protected]', 'FromNate');
  22.  
  23.  
  24. // Add a recipient
  25. $mail->addAddress('[email protected]');
  26.  
  27.  
  28. // Email subject
  29. $mail->Subject = 'Send Email via SMTP using PHPMailer';
  30.  
  31. // Set email format to HTML
  32. $mail->isHTML(true);
  33.  
  34. // Email body content
  35. $mailContent = '
  36.    <h2>Send HTML Email using SMTP Server in PHP</h2>
  37.    <p>It is a test email by CodexWorld, sent via SMTP server with PHPMailer using PHP.</p>
  38.    <p>Read the tutorial and download this script from <a href="https://www.codexworld.com/">CodexWorld</a>.</p>';
  39. $mail->Body = $mailContent;
  40.  
  41. // Send email
  42. if(!$mail->send()){
  43.     echo 'Message could not be sent. Mailer Error: '.$mail->ErrorInfo;
  44. }else{
  45.     echo 'Message has been sent.';
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement