Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Import PHPMailer classes into the global namespace
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- // Include PHPMailer library files
- require 'vendor/autoload.php';
- // Create an instance of PHPMailer class
- $mail = new PHPMailer(true);
- // SMTP configuration
- $mail->isSMTP();
- $mail->Host = 'smtp.mailgun.org';
- $mail->SMTPAuth = true;
- $mail->Password = '1645e3da6b516b3220e6097d9432d850-73f745ed-8e219784';
- $mail->SMTPSecure = 'tls';
- $mail->Port = 587;
- // Sender info
- // Add a recipient
- // Email subject
- $mail->Subject = 'Send Email via SMTP using PHPMailer';
- // Set email format to HTML
- $mail->isHTML(true);
- // Email body content
- $mailContent = '
- <h2>Send HTML Email using SMTP Server in PHP</h2>
- <p>It is a test email by CodexWorld, sent via SMTP server with PHPMailer using PHP.</p>
- <p>Read the tutorial and download this script from <a href="https://www.codexworld.com/">CodexWorld</a>.</p>';
- $mail->Body = $mailContent;
- // Send email
- if(!$mail->send()){
- echo 'Message could not be sent. Mailer Error: '.$mail->ErrorInfo;
- }else{
- echo 'Message has been sent.';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement