// Include PHPMailer library require 'PHPMailer/src/PHPMailer.php'; // Create a new PHPMailer object $mail = new PHPMailer(); // Set SMTP credentials $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = 'your-gmail-username'; $mail->Password = 'your-gmail-password'; $mail->Port = 587; // Set email parameters $mail->setFrom('sender@example.com', 'Sender Name'); $mail->addAddress('recipient@example.com', 'Recipient Name'); $mail->Subject = 'Subject Line'; $mail->Body = 'Email content goes here.'; // Send email if (!$mail->send()) { echo 'Failed to send email: ' . $mail->ErrorInfo; } else { echo 'Email sent successfully!'; }
$email = "example@example.com"; // Validate email using filter_var function if (filter_var($email, FILTER_VALIDATE_EMAIL)) { echo 'Email is valid'; } else { echo 'Invalid email'; }These code examples demonstrate how to send an email and validate an email using PHPMailer library and filter_var function respectively.