长时间听众,第一次来电...
我最近开始研究O'Reilly关于PHP的“Head First”书籍,这是他们的一个练习 - 你们中的一些人看起来很熟悉。
本课程的目的是演示php中的“mail”功能如何工作,为此他们提供了以下代码作为示例(为简洁/上下文编辑):
$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);
---------------------------------- EDIT ------------ -----------------------
根据请求,这是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”变量连接到邮件正文,并在电子邮件正文中正确显示。
所以我不知道为什么它不能用在邮件的“to”行中。我在这里缺少什么?
答案 0 :(得分:0)
嗯,这很令人尴尬,但在消耗其他人的宝贵时间之前,我最好拥有它......
在访问PHP doc网站后,运行几个Google搜索,然后用另一组眼睛看原始代码,问题是 - 没有太多细节 - 通过添加'r'来修复。这是一个隐藏在长电子邮件地址中的TYPO。
感谢你的帮助,道森,但你没有机会!