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 do I use PHPMailer to attach a ZIP file?
- How can I configure PHPMailer to support Polish characters?
- How can I configure PHPMailer to work with GoDaddy?
- How do I use PHPMailer with Yii2?
- How do I set the X-Mailer header using PHPMailer?
- How can I use PHPMailer without SMTP secure?
- How can I use PHPMailer to send emails from my WordPress site?
- How do I determine which version of PHPMailer I'm using?
- How can I send a UTF-8 encoded email using PHPMailer?
See more codes...