我正在尝试创建一个php脚本,它将使用mySQL数据库为我处理邮件列表,我已经完成了大部分工作。不幸的是,我似乎无法使标题正常工作,我不确定问题是什么。
$headers='From: noreply@rilburskryler.net \r\n';
$headers.='Reply-To: noreply@rilburskryler.net\r\n';
$headers.='X-Mailer: PHP/' . phpversion().'\r\n';
$headers.= 'MIME-Version: 1.0' . "\r\n";
$headers.= 'Content-type: text/html; charset=iso-8859-1 \r\n';
$headers.= "BCC: $emailList";
我收到的结果是:
“noreply”@ rilburskryler.net rnReply-To:noreply@rilburskryler.netrnX-Mailer:PHP / 5.2.13rnMIME-Version:1.0
答案 0 :(得分:105)
要显示姓名,而不是显示的电子邮件地址,请使用以下内容:
"John Smith" <johnsemail@hisserver.com>
易。
关于断行换行符,这是因为您将文本括在撇号而不是引号中:
$headers = array(
'From: "The Sending Name" <noreply@rilburskryler.net>' ,
'Reply-To: "The Reply To Name" <noreply@rilburskryler.net>' ,
'X-Mailer: PHP/' . phpversion() ,
'MIME-Version: 1.0' ,
'Content-type: text/html; charset=iso-8859-1' ,
'BCC: ' . $emailList
);
$headers = implode( "\r\n" , $headers );
答案 1 :(得分:10)
在single quoted string内,只有转义序列\'
和\\
分别被'
和\
取代。您需要使用double quotes将转义序列\r
和\n
替换为相应的字符:
$headers = "From: noreply@rilburskryler.net \r\n";
$headers.= "Reply-To: noreply@rilburskryler.net\r\n";
$headers.= "X-Mailer: PHP/" . phpversion()."\r\n";
$headers.= "MIME-Version: 1.0" . "\r\n";
$headers.= "Content-type: text/html; charset=iso-8859-1 \r\n";
$headers.= "BCC: $emailList";
您还可以使用数组来收集标题字段,然后将它们放在一起:
$headers = array(
'From: noreply@rilburskryler.net',
'Reply-To: noreply@rilburskryler.net',
'X-Mailer: PHP/' . phpversion(),
'MIME-Version: 1.0',
'Content-type: text/html; charset=iso-8859-1',
"BCC: $emailList"
);
$headers = implode("\r\n", $headers);
答案 2 :(得分:-2)
$to = 'SendersName@domain.com';
$to .=', ' . $_POST['Femail'];
$subject = 'Contact Us Form';
// message
$message ="<html>
<head>
<title>Email title</title>
</head>
<body>
<h3>important message follows</h3>
<div>
you are being brought this email to be safe.
</div>
</body>
</html>";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: SendersEmailName <SendersEmailName@domain.com>' . "\r\n";
$headers .= 'From: YourName <YourName@domain.com>' . "\r\n";
$headers.='X-Mailer: PHP/' . phpversion()."\r\n";
$headers.= "BCC: $emailList";
mail($to, $subject, $message, $headers);