doubi1624 2013-05-03 16:58
浏览 65
已采纳

php变量没有被传递给mail()“to line”参数

long time listener, first time caller...

I have recently started working through O'Reilly's "Head First" books on PHP, and this is one of their exercises - the code may look familiar to some of you.

The goal of the lesson was to demonstrate how the "mail" function in php works, and to that end they gave the following code to use as an example (edited for brevity/context):

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

----------------------------------EDIT-----------------------------------

Per request, here is the results of 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

Everything works as expected except that I would receive no emails after filling out and submitting the form.

After removing the $to variable from "mail()" and replacing it with a static string ('myemail@myemail.com') I did get a properly formatted email.

I also concatenated the "$to" variable to the body of the message and it displayed correctly from within the email body.

So I am at a loss as to why it cannot be used in the mail's "to" line. What am I missing here?

  • 写回答

1条回答 默认 最新

  • douzhui8531 2013-05-05 12:55
    关注

    Well, this is embarrassing, but it's best I own up to it before consuming other people's valuable time...

    After going to the PHP doc site, running several Google searches, and having another set of eyes look at the original code, the problem was - without going into too much detail - fixed by adding an 'r'. It was a TYPO hidden in a long email address.

    Thanks for your help, Dawson, but you never had a chance!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算