发出PHP邮件头
我在使用php mail时遇到以下问题,我将公开两种方法,以及获得和期望的结果: 案例1:发出PHP邮件头,php,Php,我在使用php mail时遇到以下问题,我将公开两种方法,以及获得和期望的结果: 案例1: $to = $EmailsPropiosPresupuestos; $subject = $txtAsuntoCliente; $message = $emailCliente; $headers .= "From: noreply\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; 我发送的电子邮件和html以正确
$to = $EmailsPropiosPresupuestos;
$subject = $txtAsuntoCliente;
$message = $emailCliente;
$headers .= "From: noreply\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
我发送的电子邮件和html以正确的方式解码,但我的“发件人”标题看起来像:noreply@124512.net“(奇怪的根)
案例2:
$to = $EmailsPropiosPresupuestos;
$subject = $txtAsuntoCliente;
$message = $emailCliente;
$headers .= "From: noreply@example.com\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
现在我的“From”标题很好noreply@example.com“,但邮件无法解码html,因此我无法以正确的方式查看邮件。尝试将MIME版本添加到邮件头:
$headers .= "MIME-Version: 1.0\n";
对于“否”回复,我建议您使用回复添加到:
$headers .= "Reply-To: noreply@example.com\n";
这将允许您保留一个更好的电子邮件地址。
在我的代码中,我在每个标题行上使用\n
,并使用\r\n
完成,来自:
示例#4发送HTML电子邮件
还可以使用mail()发送HTML电子邮件
问题是什么?我需要发送经过html解码的邮件,以及带有正确电子邮件地址的“发件人”标题noreply@example.com,我不能同时做这两件事。请尝试将\r\n
更改为\n
-有时邮件客户端在\r\n
<?php
// multiple recipients
$to = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</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: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>