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 use PHPMailer to attach a ZIP file?
- How can I configure PHPMailer to work with GoDaddy?
- How can I configure PHPMailer to support Polish characters?
- How do I check which version of PHPMailer I'm using?
- How can I set up PHPMailer to use Zimbra SMTP?
- How do I use PHPMailer to send a file?
- How do I enable debug mode in PHPMailer?
- How can I use PHPMailer SMTPDebug to debug my email sending process?
- How do I disable STARTTLS in PHPMailer?
- How do I use PHPMailer with Yii2?
See more codes...