What is the correct syntax for the "From" header in an email sent using PHP's mail function?
When sending an email using PHP's mail function, the "From" header should include the sender's email address and optionally their name. The correct syntax for the "From" header is "From: sender@example.com" or "From: Sender Name <sender@example.com>". This ensures that the email is properly identified as being sent from the specified sender.
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email.";
$headers = "From: sender@example.com";
mail($to, $subject, $message, $headers);
Keywords
Related Questions
- How can PHP be used to generate a screen output based on directory listings from a database?
- What are the potential security risks associated with sending codes via email in PHP applications?
- When restructuring existing PHP code for better clarity and functionality, what considerations should be taken into account to ensure the desired outcome is achieved without introducing new errors?