PHP邮件函数忽略其他标题
我正在尝试使用php mail()函数发送邮件 但由于某些原因,我不明白,额外的标题被忽略 这是我的代码:PHP邮件函数忽略其他标题,php,email,contact-form,email-headers,Php,Email,Contact Form,Email Headers,我正在尝试使用php mail()函数发送邮件 但由于某些原因,我不明白,额外的标题被忽略 这是我的代码: $errors = ''; $myemail = 'my@email.com'; $myemail_bcc = 'my_bbc@email.com'; if(empty($_POST['nome']) || empty($_POST['email'])) { $errors .= "Error: You must fill Name a
$errors = '';
$myemail = 'my@email.com';
$myemail_bcc = 'my_bbc@email.com';
if(empty($_POST['nome']) || empty($_POST['email']))
{
$errors .= "Error: You must fill Name and Email fields";
}
$name = $_POST['nome'];
$email_address = $_POST['email'];
$telefono = $_POST['telefono'];
$message = $_POST['messaggio'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "<br />Error: You must use a valid email address";
}
// spediamo la mail
if( empty($errors))
{
$to = $myemail;
$email_subject = "New Request from: $name";
$email_body = "User data:.\n\n";
$email_body .= "Nome: $name \nEmail: $email_address \nTelefono: $telefono \n";
$email_body .= "Messaggio: \n$message";
$headers = "From: John Smith <$myemail>\r\n";
$headers .= "Reply-To: $name <$email_address>\r\n";
$headers .= "Bcc: $myemail_bcc";
mail($to,$email_subject,$email_body,$headers);
}
甚至在一条线上
$headers = "From: $myemail\r\nReply-To: $name <$email_address>\r\nBcc: $myemail_bcc";
$headers=“From:$myemail\r\n提交至:$name\r\nBcc:$myemail\u bcc”;
但在任何情况下,邮件都不会发送到密件抄送地址,客户端电子邮件中的“回复”功能也不会使用“回复到”地址
我错在哪里?您是否尝试过使用
PHP\u EOL
常量而不是\r\n
?另一方面,请务必注意。我曾经遇到过类似的情况,并且被告知要声明$headers。='MIME版本:1.0'。“\r\n”$标题。='内容类型:文本/普通;字符集=iso-8859-1'。“\r\n”;对于未来的读者,您绝对不想使用PHP\u EOL
。
$headers = "From: $myemail\r\nReply-To: $name <$email_address>\r\nBcc: $myemail_bcc";