PHP email - From header Print

  • 20

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

You can change that by adding the following code:
$headers = 'From: user@yourdomain.com' . "\r\n" .
'Reply-To: user@yourdomain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();


Then just add $headers to the mail function.

You can also add CC and BCC to your emails by adding this code:
$headers = 'From: user@yourdomain.com' . "\r\n" .
'Cc: 'user@hisdomain.com' . "\r\n" .
'Bcc: 'user@herdomain.com' . "\r\n" .
'Reply-To: user2@yourdomain.com' . "\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);
Related Articles


Was this answer helpful?

« Back