PHP email - From header

Your PHP mail() script emails always show "From: cPanel-username@servername".

You can change that by adding the following code:

$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

Then just add $headers to the mail function. See the related article for a complete script.

You can also add CC and BCC to your emails by adding this code:

$headers = 'From: [email protected]' . "\r\n" .
'Cc: '[email protected]' . "\r\n" .
'Bcc: '[email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

IMPORTANT - You must add the header variable as the 4th attribute in the mail() function. EXAMPLE - mail($to, $subject, $message, $headers);

  • 17 Users Found This Useful
Was this answer helpful?