email() with header information
Hi,
I am trying to send email using mail() with the following header information. However the email goes from [email protected]. How do I get my mail script to send email from my email id instead of [email protected].
$headers = "From: XXXX <[email protected]>"."\n"."MIME-Version:1.0"."\r\n"."Content-type:text/html; charset=iso-8859-1"."\r\n"."X-Priority: 3"."\n"."X-MSMail-Priority: Normal"."\n"."X-Mailer: xxx"."\n"."X-MimeOLE: Produced By xxx";
mail($email, $subject, $read, $headers);
Please help.
Re: email() with header information
You've a mix of \n and \r\n between your headers. SMTP headers are delimited by \r\n.
Re: email() with header information
Thank you for the reply penagate. But this is not working. I remove all "\r\n" and there is no error mail in my inbox. Please try to cope up the situation. Thank you so much.
Re: email() with header information
No no no. The \r\n separators are required.
Try this:
$headers = "From: XXXX <[email protected]>\r\n".
"MIME-Version:1.0\r\n".
"Content-type:text/html; charset=iso-8859-1\r\n".
"X-Priority: 3\r\n".
"X-MSMail-Priority: Normal\r\n".
"X-Mailer: xxx\r\n".
"X-MimeOLE: Produced By xxx\r\n";
Sorry if I misled you.
P.S. Alternatively, you can put headers into an array, and then join them into a string. This is more manageable than hard-coding one long string.
PHP Code:
$headers = array(
'From: XXXX <[email protected]>',
'MIME-Version:1.0',
'Content-type:text/html; charset=iso-8859-1',
'X-Priority: 3',
'X-MSMail-Priority: Normal',
'X-Mailer: xxx',
'X-MimeOLE: Produced By xxx'
);
mail(... join("\r\n", $headers), ...);