What are the best practices for storing emails in a database using PHP?

When storing emails in a database using PHP, it's important to properly sanitize and validate the email data to prevent SQL injection attacks and ensure data integrity. One common practice is to use prepared statements with parameterized queries to safely insert email data into the database. Additionally, storing emails as plain text may not be the most secure option, so consider encrypting sensitive email content before storing it in the database.

// Assuming $email contains the email data to be stored in the database

// Establish a database connection
$pdo = new PDO('mysql:host=localhost;dbname=your_database', 'username', 'password');

// Prepare a SQL statement with a parameterized query
$stmt = $pdo->prepare("INSERT INTO emails (email) VALUES (:email)");

// Bind the email data to the parameter
$stmt->bindParam(':email', $email);

// Execute the query
$stmt->execute();