What are common issues with sending emails from a textarea using the mail() function in PHP?
Common issues with sending emails from a textarea using the mail() function in PHP include potential injection attacks through the textarea input and formatting issues with the email content. To solve these issues, it is important to properly sanitize and validate the textarea input before using it in the email message. Additionally, make sure to properly format the email content to ensure it displays correctly in the recipient's inbox.
// Sanitize and validate the textarea input
$textarea_input = filter_var($_POST['textarea_input'], FILTER_SANITIZE_STRING);
// Format the email content
$email_message = wordwrap($textarea_input, 70, "\r\n");
// Send the email
$to = 'recipient@example.com';
$subject = 'Email Subject';
$headers = 'From: sender@example.com';
mail($to, $subject, $email_message, $headers);