長年のリスナー、初めての電話者...
私は最近、PHP に関する O'Reilly の「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」変数をメッセージの本文に連結すると、メール本文内から正しく表示されました。
では、なぜメールの「to」行で使えないのか途方に暮れています。ここで何が欠けていますか?