phpmailerHow can I use PHPMailer to validate email addresses?
PHPMailer is a library that can be used to validate email addresses. It provides a set of functions to validate the syntax of email addresses, check if the domain part of the address exists, and check if the email address can receive messages.
Example code
<?php
// include the PHPMailer library
require 'PHPMailer/PHPMailerAutoload.php';
// create a new PHPMailer object
$mail = new PHPMailer();
// validate an email address
$valid = $mail->validateAddress('[email protected]');
if ($valid) {
echo 'The email address is valid';
} else {
echo 'The email address is not valid';
}
Output example
The email address is valid
The code above uses the following parts:
require 'PHPMailer/PHPMailerAutoload.php'
- This line includes the PHPMailer library.$mail = new PHPMailer()
- This line creates a new PHPMailer object.$valid = $mail->validateAddress('[email protected]')
- This line validates the email address[email protected]
.if ($valid) {...} else {...}
- This block checks the result of the validation and prints a message.
For more information, see the PHPMailer documentation.
More of Phpmailer
- How do I configure PHPmailer to use Zoho SMTP?
- How can I configure PHPMailer to support Polish characters?
- How do I use PHPMailer to attach a ZIP file?
- How can I configure PHPMailer to work with GoDaddy?
- How can I use PHPMailer with React?
- How do I use PHPMailer to encode emails in UTF-8?
- How do I use PHPMailer to send emails through Namecheap?
- How do I use PHPMailer with IMAP?
- How can I use PHPMailer with Bitrix?
- How do I use PHPMailer with Yii2?
See more codes...