0

长时间的听众,第一次来电......

我最近开始阅读 O'Reilly 的关于 PHP 的“Head First”书籍,这是他们的练习之一——代码对你们中的某些人来说可能看起来很熟悉。

本课的目的是演示 php 中的“邮件”函数是如何工作的,为此他们提供了以下代码作为示例(为简洁/上下文而编辑):

$email = $_POST['email'];
$to = 'myemail@myemail.com';
$subject = 'Abduction report';
$message = "$name .  was abducted $when_it_happened  and was gone for $how_long . \n" .
"Number of aliens: $how_many \n" .
"Alien description $alien_description\n" . 
"What they did: $what_they_did \n" .
"Fang spotted: $fang_spotted \n" .
"Other comments: $other";
mail($to, $subject, $message, 'From:' . $email);

- - - - - - - - - - - - - - - - - 编辑 - - - - - - - - --------------------

根据请求,以下是结果phpinfo()

System: Linux infong 2.4 #1 SMP Thu Feb 14 13:02:49 CET 2013 i686 GNU/Linux

Build date: Apr 10 2013 13:38:50

Configure Command: '../configure' '­­program­suffix=5' '­­with­pear=/usr/lib/php5' '­­with­    config­file­path=/usr/lib/php5' '­­with­libxml­dir' '­­with­mysqli' '­­with­kerberos' '­­with­imap­ssl' '­­enable­soap' '­­with­xsl' '­­enable­mbstring=all' '­­with­curl' '­­with­mcrypt' '­­with­gd' '­­with­pdo­mysql' '­­with­freetype­dir' '­­with­libxml­dir' '­­with­mysql' '­­with­zlib' '­­enable­debug=no' '­­enable­safe­mode=no' '­­enable­discard­path=no' '­­with­png­dir' '­­enable­track­vars' '­­with­db' '­­with­gdbm' '­­enable­force­cgi­redirect' '­­enable­fastcgi' '­­with­ttf' '­­enable­ftp' '­­enable­dbase' '­­enable­memory­limit' '­­enable­calendar' '­­enable­wddx' '­­with­jpeg­dir=/usr/src/kundenserver/jpeg­6b' 'enable­bcmath' '­­enable­gd­imgstrttf' '­­enable­shmop' '­­enable­mhash' '­­with­mhash' '­­with­openssl' '­­enable­xslt' '­­with­xslt­sablot' '­­with­dom' '­­with­dom­xslt' '­­with­dom­exslt' '­­with­imap' '­­with­iconv' '­­with­bz2' '­­with­gettext' '­­enable­exif' '­­with­idn' '­­with­sqlite' '­­enable­sqlite­utf8' '­­enable­zip' '­­with­tidy' '­­enable­gd­native­ttf'

Server API: CGI/FastCGI

Virtual Directory Support: disabled

Configuration File (php.ini) Path: /usr/lib/php5

Loaded Configuration File: /usr/lib/php5/php.ini

Scan this dir for additional .ini files: (none)

additional .ini files parsed: (none)

PHP API: 20041225

PHP Extension: 20060613

Debug Build: no

Thread Safety: disabled

Zend Memory Manager: enabled

IPv6 Support: enabled

Registered PHP Streams: https, ftps, compress.zlib, compress.bzip2, php, file, data, http, ftp, zip

Registered Stream Socket Transports: tcp, udp, unix, udg, ssl, sslv3, sslv2, tls

Registered Strem Filters: zlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed

一切都按预期工作,只是在填写并提交表格后我不会收到任何电子邮件。

从“mail()”中删除 $to 变量并将其替换为静态字符串 ('myemail@myemail.com') 后,我确实收到了格式正确的电子邮件。

我还将“$to”变量连接到邮件正文,并在电子邮件正文中正确显示。

所以我不知道为什么不能在邮件的“收件人”行中使用它。我在这里想念什么?

4

1 回答 1

0

好吧,这很尴尬,但在消耗别人宝贵的时间之前,我最好承认这一点……

在访问 PHP 文档站点、运行几个 Google 搜索并用另一组眼睛查看原始代码后,问题是 - 无需过多详细说明 - 通过添加“r”来解决。这是一个隐藏在一个长电子邮件地址中的 TYPO。

谢谢你的帮助,道森,但你从来没有机会!

于 2013-05-05T12:55:58.683 回答