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' '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
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?