长时间的听众,第一次来电......
我最近开始阅读 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' 'programsuffix=5' 'withpear=/usr/lib/php5' 'with configfilepath=/usr/lib/php5' 'withlibxmldir' 'withmysqli' 'withkerberos' 'withimapssl' 'enablesoap' 'withxsl' 'enablembstring=all' 'withcurl' 'withmcrypt' 'withgd' 'withpdomysql' 'withfreetypedir' 'withlibxmldir' 'withmysql' 'withzlib' 'enabledebug=no' 'enablesafemode=no' 'enablediscardpath=no' 'withpngdir' 'enabletrackvars' 'withdb' 'withgdbm' 'enableforcecgiredirect' 'enablefastcgi' 'withttf' 'enableftp' 'enabledbase' 'enablememorylimit' 'enablecalendar' 'enablewddx' 'withjpegdir=/usr/src/kundenserver/jpeg6b' 'enablebcmath' 'enablegdimgstrttf' 'enableshmop' 'enablemhash' 'withmhash' 'withopenssl' 'enablexslt' 'withxsltsablot' 'withdom' 'withdomxslt' 'withdomexslt' 'withimap' 'withiconv' 'withbz2' 'withgettext' 'enableexif' 'withidn' 'withsqlite' 'enablesqliteutf8' 'enablezip' 'withtidy' 'enablegdnativettf'
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”变量连接到邮件正文,并在电子邮件正文中正确显示。
所以我不知道为什么不能在邮件的“收件人”行中使用它。我在这里想念什么?