$from_email = 'sender@example.com'; $from_name = 'John Smith'; $headers = 'From: ' . $from_name . ' <' . $from_email . '>'; mail($to_email, $subject, $message, $headers);
$from_email = 'sender@example.com'; mail($to_email, $subject, $message, 'From: ' . $from_email);In this example, we're setting the sender's email address only, without providing a display name. This can sometimes be useful if you want to keep the email as anonymous as possible. Package Library: PHPMailer PHPMailer is a popular package library for sending email messages in PHP scripts. It provides convenient functions for commonly used features such as setting the sender's email address and name, adding attachments, and sending HTML email. The PHP Mail setFrom function is typically used in conjunction with PHPMailer to set the sender's email address in the email message.