What are some recommended resources or libraries for handling email functionality in PHP?
One recommended resource for handling email functionality in PHP is the PHPMailer library. PHPMailer provides a clean and simple way to send emails from a PHP application, with support for attachments, HTML emails, and SMTP authentication. Another option is the Swift Mailer library, which offers similar features and is widely used in PHP applications for sending emails.
// Using PHPMailer library for sending emails
require 'vendor/autoload.php';
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->SMTPAuth = true;
$mail->Username = 'your@example.com';
$mail->Password = 'yourpassword';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('from@example.com', 'Your Name');
$mail->addAddress('recipient@example.com', 'Recipient Name');
$mail->isHTML(true);
$mail->Subject = 'Subject';
$mail->Body = 'Email content here';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}