use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; // Create a new PHPMailer instance $mail = new PHPMailer(true); try { // Set the mailer to use SMTP $mail->isSMTP(); // Set the SMTP server and login credentials $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = 'your-email@gmail.com'; $mail->Password = 'your-email-password'; $mail->SMTPSecure = 'tls'; $mail->Port = 587; // Set the recipient, subject, and message body $mail->setFrom('your-email@gmail.com', 'Your Name'); $mail->addAddress('recipient-email@gmail.com', 'Recipient Name'); $mail->Subject = 'Testing PHPMailer'; $mail->Body = 'This is a test email sent using PHPMailer.'; // Send the email $mail->send(); echo 'Email sent successfully!'; } catch (Exception $e) { echo 'Email could not be sent. Error: ' . $mail->ErrorInfo; }
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; // Create a new PHPMailer instance $mail = new PHPMailer(true); try { // Set the mailer to use SMTP $mail->isSMTP(); // Set the SMTP server and login credentials $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = 'your-email@gmail.com'; $mail->Password = 'your-email-password'; $mail->SMTPSecure = 'tls'; $mail->Port = 587; // Set the recipient, subject, and message body $mail->setFrom('your-email@gmail.com', 'Your Name'); $mail->addAddress('recipient-email@gmail.com', 'Recipient Name'); $mail->Subject = 'Testing PHPMailer'; $mail->Body = 'This is a test email sent using PHPMailer.'; // Attach a file to the email $attachment = __DIR__ . '/test.pdf'; $mail->addAttachment($attachment, 'test.pdf'); // Send the email $mail->send(); echo 'Email sent successfully!'; } catch (Exception $e) { echo 'Email could not be sent. Error: ' . $mail->ErrorInfo; }This library is part of the PHPMailer package.