我正在尝试发送电子邮件目前工作正常。但是一旦我加上这一行,它就不会再发邮件了。
$headers = "Content-Type: text/html; charset=ISO-8859-1'r'n";
mail("anton@sci5.com", $subject, $message, $from, $headers )
基本上,当我添加$headers
到我的mail();
它不会工作,但如果我删除$header
它发送我的邮件,但html没有被渲染。
我做错了什么?
这是我的代码。
$subject = "E-newsletter Signup";
$message = "$todayis [EST] 'n
From: $firstname $lastname ($email)'n
$firstname $lastname has subscribe for the ff. e-newsletters:'n
" ;
if (!empty($ivpump1)) { $message .= "$ivpump1'n"; }
if (!empty($fetal1)) { $message .= "$fetal1'n"; }
if (!empty($biomed1)) { $message .= "$biomed1'n"; }
$message.= "<br /><br /><br />
<p><b>From Webpage :</b> $fromWebpage </p>
<p><b>From Google Keyword :</b> $refKeyword</p>
<p><b>Referring Page :</b> $refPage</p>
<p><b>From IP Address :</b> $endUserIP</p>";
$from = "From: $email'r'n";
$headers = "Content-Type: text/html; charset=ISO-8859-1'r'n";
mail("anton@gmail.com", $subject, $message, $from, $headers );
header("Location: http://www.site.com/thank-you-settings.html");
尝试在标题中添加From: $from'r'n
,然后在引号中添加Content-Type
,并在调用邮件函数时去掉from
参数。除非您在php.ini中设置默认的from
,或者使用additional_parameters
参数(第五个),否则如果您想设置'from'值,该函数有四个强制参数,其中最后一个是headers
。似乎您的from
正在满足headers
参数的要求,但是一旦您添加第五个参数,您就错误地使用了该函数。
需要检查邮件功能的签名http://www.php.net/manual/en/function.mail.php
是mail($to,$subject,$message, $headers)
。你打错了。
$headers
需要:
$headers = "From: me@me.com'r'n";
$headers .= "Content-Type: text/html; charset=utf-8'r'n";
-
正确邮件签名功能。
mail($to,$subject,$message, $headers)
-
$header必须是:
$headers .= "Content-Type: text/html; charset=ISO-8859-1'r'n";
-
一个很好的例子Html电子邮件与php:http://css-tricks.com/sending-nice-html-email-with-php/
-
如果html渲染不工作,那么原因是:
不幸的是,很多电子邮件客户端不尊重标题中的html或css文件。所有内容都需要内联。gmail和outlook也会出现这个问题。
'headers'和'from'必须是同一个变量的一部分,试试这个:
<?php
$mime_boundary=md5(time());
$headers .= 'From: My Email <me@company.com>' . "'n";
$headers .= 'MIME-Version: 1.0'. "'n";
$headers .= "Content-Type: multipart/mixed; boundary='"".$mime_boundary."'"". "'n";
$msg .= "--".$mime_boundary. "'n";
$msg .= "Content-Type: text/plain; charset=iso-8859-1". "'n";
$msg .= "Content-Transfer-Encoding: 7bit". "'n'n";
$msg .= $textmessage . "'n'n";
$msg .= "--".$mime_boundary. "'n";
$msg .= "Content-Type: application/pdf; name='"".$filename."'"". "'n";
$msg .= "Content-Transfer-Encoding: base64". "'n";
$msg .= "Content-Disposition: attachment; filename='"".$filename."'"". "'n'n";
$msg .= chunk_split(base64_encode($doc)) . "'n'n";
$msg .= "--".$mime_boundary."--". "'n'n";
mail("anton@sci5.com", $subject, $msg ,$headers );
?>
在你发送PDF的例子中,你可以发送图像或任何其他文件,只需要发送正确的"Content-Type:
,如application/PDF for PDF
更多信息:http://rob.sun3.org/archives/107