To change the "From:" email address in the mail()
function in PHP, you can use the additional_headers
parameter to specify a custom "From:" header.
Here's an example of how to use the additional_headers
parameter to specify a custom "From:" email address in the mail()
function:
$to = "recipient@example.com"; $subject = "Test email"; $message = "This is a test email."; $headers = "From: sender@example.com\r\n"; mail($to, $subject, $message, $headers);
This will send an email with the "From:" address set to "sender@example.com".
You can also specify additional headers in the $headers
variable, such as the "Cc:" and "Bcc:" headers. For example:
$to = "recipient@example.com"; $subject = "Test email"; $message = "This is a test email."; $headers = "From: sender@example.com\r\nCc: cc_recipient@example.com\r\nBcc: bcc_recipient@example.com\r\n"; mail($to, $subject, $message, $headers);