Before you can send email from your PHP script, you must first ensure that your copy of PHP has been correctly configured. If You Are Using PHP on UNIXTo send email from a PHP script running on UNIX, you must have a sendmail-compatible MTA installed on the same server that your PHP script runs on. On UNIX systems, PHP sends email by running the command-line program sendmail. sendmail is the de facto standard MTA for UNIX systems. If you are using an alternative to sendmail, it must provide a sendmail wrapper. A sendmail wrapper is a drop-in replacement for the sendmail command-line program. It must accept the -t and -i command-line switches at the very least. When PHP is compiled, the configure script searches for the sendmail command in /usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/ If configure cannot find the sendmail command, then sendmail support will be permanently disabled. The following PHP functions will either be missing entirely, or will always return an error:
When this happens, you must install a sendmail wrapper, and then recompile PHP. Once PHP is compiled with sendmail support enabled, whenever your script sends email, PHP will use the sendmail command discovered by the configure script. If you ever need to override this default, set the sendmail_path in php.ini to point to the sendmail command that you want PHP to use. sendmail_path = '/usr/local/bin/sendmail'If You Are Using PHP on Windows or Netware Although not documented in the PHP Manual, if you set the sendmail_path setting in your php.ini file, PHP will attempt to send email via the sendmail_wrapper—behaving exactly as if PHP were running on UNIX. This can catch you out, so remember to look for it when troubleshooting email problems. If you do not have a sendmail wrapper available, PHP on Windows talks to the mail transport agent (MTA) directly via the SMTP network protocol. PHP needs to be configured to tell it where to find your MTA:
PHP on Windows does not support SASL. If your MTA is configured to require authentication, you will need to change the security on your MTA to enable PHP to send emails through successfully. On UNIX, the MTA will automatically say that the email is from whichever user your PHP script is running as. This can't be done on Windows because PHP is connecting to the MTA over the network via SMTP. Instead, PHP will work out who the email is from by looking in these places in this order:
PHP will display an error and refuse to send the email if it cannot determine who the email is from. If you compile your own version of PHP on Windows, and you are going to use it to send emails, it's important that you build PHP with the Perl-compatible regular expression (PCRE) library included. PHP on Windows relies on the PCRE functions to make sure that headers have the correct end of line character. If you build PHP on Windows without PCRE support, you might find that MTAs refuse to accept your emails for delivery. With PHP correctly configured, you can now send email from your PHP scripts.
blog comments powered by Disqus |