I am not able to send email through PHP mail function while I specify an array of $headers as
$headers = array (
'From' => "info@mysite.com",
'Content-type' => "text/html;charset=UTF-8"
);
or
$headers=array(
'From: "info@mysite.com',
'Content-Type:text/html;charset=UTF-8',
'Reply-To: "info@mysite.com'
);
and here is the code
<?php
$email = 'test@test.com';
$headers=array(
'From: "info@mysite.com',
'Content-Type:text/html;charset=UTF-8',
'Reply-To: info@mysite.com'
);
$msg= 'This is a Test';
mail($email, "Call Back Requert Confirmation", $msg, $headers);
?>
can you please let me know why this is happening? and how I can fix this?
If you want to send $headers
through array, then you need to add to the end of each header value and convert the array into a
string
.
Your code should be:
$headers = array(
'From: <info@mysite.com>',
'Content-Type:text/html;charset=UTF-8',
'Reply-To: <info@mysite.com>'
);
$headers = implode("
", $headers);
$headers
needs to be a string, not an array:
http://php.net/manual/en/function.mail.php
$headers =
'From: info@mysite.com' . "
" .
'Reply-To: webmaster@example.com' . "
" .
'MIME-Version: 1.0' . "
" .
'Content-type: text/html; charset=iso-8859-1' . "
"
;
mail($email, "Call Back Requert Confirmation", $msg, $headers);
If you want to keep $headers
as an array, you can also do
mail($email, "Call Back Requert Confirmation", $msg, implode("
", $headers));
try to send headers as string not an array
$headers = "From: info@mysite.com
";
$headers.= "MIME-Version: 1.0
";
$headers.= "Content-Type:text/html;charset=UTF-8
";
or using array convert array in string using implode()
and send it to mail()
$headers = implode("
", $headers);
mail($email, "Call Back Requert Confirmation", $msg, $headers);