How can PHP be used to encrypt sensitive data before sending it via email?

Sensitive data can be encrypted using PHP before sending it via email to ensure its security during transmission. One way to achieve this is by using PHP's built-in encryption functions, such as openssl_encrypt(). This function allows you to encrypt the data using a specified encryption method and key before sending it in an email.

// Sensitive data to be encrypted
$data = "This is sensitive data";

// Encryption key
$key = "myEncryptionKey";

// Encryption method
$method = "AES-256-CBC";

// Encrypt the data
$encryptedData = openssl_encrypt($data, $method, $key, 0, $key);

// Send the encrypted data via email
// Code to send email here