Plesk

PHP mail() cannot send mail on Plesk server: The user user is not allowed to send email

Symptoms

Cause

Plesk bug PPPM-12408. In the /var/log/maillogthe following error can be found:

Rejecting message: system user is not allowed to send mail

Resolution

As a workaround:

Click on a section to expand

Via GUI:

  1. Log in to Plesk
  2. Go to Domains > example.com > Mail tab > Mail settingsĀ 
  3. Check the Activate mail service on this domain option and click Apply

  4. UncheckĀ  Activate mail service on this domain option and click OK

Via CLI:

  1. Connect to the server via SSH
  2. Execute the following command to enable and disable mail service for domain:

    # plesk bin mail --create-service example.com && plesk bin mail --off example.com

For all domains:

  1. Connect to the server via SSH
  2. Create script phpmail.sh and start editing it:

    # vi /root/phpmail.sh

  3. Add the following content to it and save changes:

    #!/bin/bash
    echo "--------------" >> /tmp/event_handler.log
    /bin/date >> /tmp/event_handler.log
    /usr/bin/id >> /tmp/event_handler.log
    PLAN_NAME=$(plesk bin site --info ${NEW_DOMAIN_NAME} | egrep Subscription Information -A5 | egrep service plan | cut -d'"' -f2)
    MAIL_ACTIVE=$(plesk bin service_plan --info "$PLAN_NAME" | egrep Settings -A5 | egrep Mail | awk '{print $2}')
    echo "${NEW_DOMAIN_NAME} -> $PLAN_NAME / Mail Service = $MAIL_ACTIVE" >> /tmp/event_handler.log
    if [ "$MAIL_ACTIVE" == "false" ]; then
    echo "ACTION => Create service + switch off" >> /tmp/event_handler.log
    plesk bin mail --create-service ${NEW_DOMAIN_NAME}
    plesk bin mail --off ${NEW_DOMAIN_NAME}
    fi
    echo "--------------" >> /tmp/event_handler.log

  4. Make the script executable:

    # chmod +x /root/phpmail.sh

  5. Log in to Plesk
  6. Go to Tools&Settings > Event Manager > Add event handler and add the event as follows:
  7. Click OK to save changes.