电子邮件标题“格式错误”当使用 php 中的 sendmail 命令时。为什么?
我在使用 sendmail 命令时遇到问题。
我正在从数据库调用中提取值,它们看起来不错。 邮件命令如下所示:
sendmail(urldecode($row['tracker']),urldecode($row['recipient']),urldecode($row['docurl']),urldecode($row['last_accessed']));
function sendmail($vtracker,$vrecip,$vrawurl,$viewed){
$to = $vtracker;
$subject = $vrecip . " has viewed the presentation you sent them.</br>";
$body= "Full document url: " . $vrawurl . "<br/>".
"Time and Date Viewed: :" .$viewed ;
if (!mail($to, $subject, $body)) {
echo("<p>Message delivery failed...</p>");
}
}
我回显了所有变量,它们看起来正常:
$vtracker: Bob ;
$vrecip : [email protected] ;
$vrawurl : https://docs.google.com/a/advetel.com/present/edit?id=0Ac_KwUsBMiw8ZGN2Z3N3cDlfMTc3c2Jubng0Z2Q ;
$viewed : Mon, 20 Feb 2012 10:36:22 CST ;
我收到一个如下所示的错误(从服务器上的错误日志中检索)。
[error] [client 66.249.68.23] File does not exist: /var/chroot/home/content/m/3/s/m3sglobal/html/broadband/missing.html
[Tue Feb 21 20:17:15 2012] [error] [client 70.113.8.83] Failed loading /usr/local/zo/4_3/ZendOptimizer.so: /usr/local/zo/4_3/ZendOptimizer.so: undefined symbol: empty_string
[Tue Feb 21 20:17:17 2012] [error] [client 70.113.8.83] malformed header from script. Bad header=/home/content/m/3/s/m3sglobal/: Nitrofill_Presentation.php
为什么标题“格式错误”?
I'm having trouble with a sendmail command.
I'm pulling the values out of a database call, and they look good.
The mail command looks like this:
sendmail(urldecode($row['tracker']),urldecode($row['recipient']),urldecode($row['docurl']),urldecode($row['last_accessed']));
function sendmail($vtracker,$vrecip,$vrawurl,$viewed){
$to = $vtracker;
$subject = $vrecip . " has viewed the presentation you sent them.</br>";
$body= "Full document url: " . $vrawurl . "<br/>".
"Time and Date Viewed: :" .$viewed ;
if (!mail($to, $subject, $body)) {
echo("<p>Message delivery failed...</p>");
}
}
I echoed all the variables and they look ok:
$vtracker: Bob ;
$vrecip : [email protected] ;
$vrawurl : https://docs.google.com/a/advetel.com/present/edit?id=0Ac_KwUsBMiw8ZGN2Z3N3cDlfMTc3c2Jubng0Z2Q ;
$viewed : Mon, 20 Feb 2012 10:36:22 CST ;
I'm getting an error (retrieved from the error log on the server) that looks like this.
[error] [client 66.249.68.23] File does not exist: /var/chroot/home/content/m/3/s/m3sglobal/html/broadband/missing.html
[Tue Feb 21 20:17:15 2012] [error] [client 70.113.8.83] Failed loading /usr/local/zo/4_3/ZendOptimizer.so: /usr/local/zo/4_3/ZendOptimizer.so: undefined symbol: empty_string
[Tue Feb 21 20:17:17 2012] [error] [client 70.113.8.83] malformed header from script. Bad header=/home/content/m/3/s/m3sglobal/: Nitrofill_Presentation.php
Why is the header "malformed"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为多花点时间研究 RFC 2822 也没什么坏处。
您的
to
字段由Bob
填充。这不是一个合法地址。有效电子邮件地址的格式相当复杂,但如今,地址通常采用localpart@domain
形式。 (旧格式允许通过%
用户名说明符或!
bang-paths 通常不受支持;username@[]
在不同的服务器或配置上可能受支持,也可能不受支持。必须是一个@
在电子邮件地址中,以将本地部分与域分开。)您似乎还在使用用户提供的数据,但未确认其未执行标头注入攻击。 (另请参阅 suhosin 项目有关
suhosin.mail 的文档。保护
。)您的
subject
字段包含
,这是毫无意义的,因为Subject:
标题被解释为纯文本。该字段似乎也使用数据库提供的原始数据。邮件正文还包含
,这是毫无意义的,因为您的邮件不包含任何 MIME 标记,指示text/html
内容。I think it wouldn't hurt to spend a bit more time with RFC 2822.
Your
to
field is populated withBob
. That it not a legal address. The format of valid email addresses is quite complicated but these days, addresses generally are of the formlocalpart@domain
. (Older formats that allowed delivery to UUCP addresses via%
username specifiers or!
bang-paths are often not supported; further,username@[<ip address>]
may or may not be supported on different servers or configurations. In general, there must be an@
in an email address to separate the local part from the domain.)You also appear to be using user-supplied data without any confirmation that it isn't performing header injection attacks. (See also the suhosin project's documentation about
suhosin.mail.protect
.)Your
subject
field includes a</br>
, which is pointless, since theSubject:
header is interpreted as plain text. This field also appears to be using raw data supplied by the database.The message body also includes the
</br>
, which is pointless, since your message does not include any MIME markup to indicate the presence oftext/html
content.