Results 1 to 1 of 1

Thread: Unable to send mail via a PHP mail() or script

  1. #1
    Former Employee Power Poster
    Join Date
    Apr 2005
    Location
    Seattle, WA
    Posts
    140

    Default Unable to send mail via a PHP mail() or script

    Sending mail using the PHP mail() function or a script configured for sendmail requires modification of the php.ini file and a setting in WHM. The reason for this is that CPanel uses Exim as the mail server instead of Sendmail. Because of this, flags which are normally used for sendmail will behave differently with Exim.

    The most commonly used flags are '-t' and '-i'. The '-t' flag behavior is similar between Exim and Sendmail, so it is ok to use. However, the '-i' flag behavior differs between the two, so it should not be used with Exim. Since PHP is compiled to work with sendmail and has these 2 flags already incoporated, they need to be overridden through the php.ini file. Searching within the php.ini file, you will find a section concerning the mail. You will want to change the line from
    ; sendmail_path = /usr/sbin/sendmail -t -i ;
    to
    sendmail_path=/usr/sbin/sendmail -t ;
    You will need to restart apache in order for this to take effect. If you exam the /var/log/exim_mainlog and /var/log/exim_rejectlog files, you will now see that the script or PHP page connects to Exim, but is refused relaying.

    This relaying denial is a result of a setting in WHM which prevents the user nobody from sending mail, which is what scripts and PHP pages are executed as under CPanel. Within WHM under Server Settings is located the Tweak Settings option. Selecting this option will allow server settings to be modified, including the nobody relaying denied option. Within the Mail section is the entry:
    Prevent the user 'nobody' from sending out mail to remote addresses (php and cgi scripts generally run as nobody if you are not using phpsuexec and suexec respectively.)

    Deselecting this option and saving will now allow PHP pages and scripts to send mail through the server. A simple PHP page is included to test that this functionality has been enabled:

    Code:
    <?
        if (mail('Enter Email Address', 'PHP test', 'This is a test of mail().')) {
              echo "Mail successful";
            } else {
              echo "Mail failed.";
            };
    ?>
    Last edited by Lyle@Spry; 06-15-2006 at 04:40 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •