I am not able to send email through PHP mail function while I specify an array of $headers as
$headers = array (
'From' => "[email protected]",
'Content-type' => "text/html;charset=UTF-8"
);
or
$headers=array(
'From: "[email protected]',
'Content-Type:text/html;charset=UTF-8',
'Reply-To: "[email protected]'
);
and here is the code
<?php
$email = '[email protected]';
$headers=array(
'From: "[email protected]',
'Content-Type:text/html;charset=UTF-8',
'Reply-To: [email protected]'
);
$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 it's still not working: change the sender ($sender) to a local email (use the same email as used for recipient). Upload the modified php file and retry. Contact your provider if it still does not work. Tell your provider that the standard php "mail()" function returns TRUE, but not mail will be sent.
to check if it is sending mail as intended; <? php $email = "[email protected]"; $subject = "Email Test"; $message = "this is a mail testing email function on server"; $sendMail = mail($email, $subject, $message); if($sendMail) { echo "Email Sent Successfully"; } else { echo "Mail Failed"; } ?>
"\r\n"; mail($to,$subject,$message,$headers);
Just add the -f parameter to provide the sender's email and -F parameter to provide the sender's name to the mail(), all as a string.
If you want to send $headers
through array, then you need to add \r\n
to the end of each header value and convert the array into a string
.
Your code should be:
$headers = array(
'From: <[email protected]>',
'Content-Type:text/html;charset=UTF-8',
'Reply-To: <[email protected]>'
);
$headers = implode("\r\n", $headers);
try to send headers as string not an array
$headers = "From: [email protected]\r\n";
$headers.= "MIME-Version: 1.0\r\n";
$headers.= "Content-Type:text/html;charset=UTF-8\r\n";
or using array convert array in string using implode()
and send it to mail()
$headers = implode("\r\n", $headers);
mail($email, "Call Back Requert Confirmation", $msg, $headers);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With