//include PHPMailer library require 'PHPMailer/PHPMailerAutoload.php'; //create new PHPMailer object $mail = new PHPMailer; //retrieve mailer object $smtp = $mail->getMailer(); //set SMTP settings $smtp->Host = 'smtp.gmail.com'; $smtp->Port = 587; $smtp->SMTPSecure = 'tls'; $smtp->SMTPAuth = true; $smtp->Username = 'your-email@gmail.com'; $smtp->Password = 'your-password'; //send email $mail->setFrom('your-email@gmail.com', 'Your Name'); $mail->addAddress('recipient-email@example.com'); $mail->Subject = 'Test Email'; $mail->Body = 'This is a test email sent using PHPMailer with SMTP settings.'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message sent successfully.'; }
//include Swift Mailer library require_once 'path/to/lib/swift_required.php'; //create new Swift_Transport object $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'tls') ->setUsername('your-email@gmail.com') ->setPassword('your-password'); //create new Swift_Mailer object using transport object $mailer = Swift_Mailer::newInstance($transport); //retrieve mailer object $swiftmailer = $mailer->getTransport(); //create new Swift_Message object $message = Swift_Message::newInstance('Test Email') ->setFrom(array('your-email@gmail.com' => 'Your Name')) ->setTo(array('recipient-email@example.com')) ->setBody('This is a test email sent using Swift Mailer with SMTP settings.'); //send email if (!$mailer->send($message, $failures)) { echo "Failed to send email:\n"; print_r($failures); } else { echo "Email sent successfully.\n"; }In this example, we are using the Swift Mailer library to send an email with SMTP settings. Before sending the email, we create a transport object and configure the SMTP settings. Then, we create a mailer object using the transport object and retrieve the mailer object using the getTransport() function. Finally, we create a message object and send the email using Swift Mailer's send() method. Package Library: Swift Mailer