Article ID: 129341, created on Aug 27, 2016, last review on Aug 27, 2016

  • Applies to:
  • Plesk Automation 11.1
  • Plesk Automation 11.5


Custom php.ini file for a customer's website was configured to use an external SMTP server:

[mail function]
smtp_port = 25

However, the website unable to send emails.


The PHP mail() function behaves different depending on operation system.

On Linux servers only local sendmail binary can be used. Default /etc/php.ini has the lines below with comments:

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from =

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail -t -i

So, an external SMTP can be defined only for PHP running on Windows. For PHP running on Linux only possible to replace default sendmail binary with another software sending mail.


It is possible to use external SMTP server in PHP running on Linux using a small utility called msmtp instead of standard sendmail:

  1. Install msmtp

    # yum install msmtp
  2. Create /etc/msmtprc file
  3. Set permissions as below to allow the web server reading configuration:

    # chown apache /etc/msmtprc
    # chmod 600 /etc/msmtprc
  4. Add the lines as below to the file:

    account example
    tls on
    tls_starttls off
    auth on
    password mysecretpassword


    • account - the account (or profile) name. msmtp supports multiple accounts, it is also possible to define default account in msmtprc, which would be used by msmtp in case account name is not specified in command line (see the example below on step 5.3)
    • host - remote SMTP server
    • user - client's login to SMTP server
  5. Test msmtp settings:

    5.1. Create test email file

    # vi test_email

    5.2. Paste a text like below:

    From: Test User <test@mydomain.tld>
    To: John <john@domain.tld>
    Subject: Test
    This is a test message

    5.3. to send the message run:

    # cat test_email | msmtp -a example john@domain.tld

    Note: the -a key forces msmtp to use mail settings from the exampleaccount.

  6. Edit the custom php configuration file, for example /var/www/vhosts/system/customer-web-site.tld/etc/php.ini:

    Search and edit the sendmail_path:

    sendmail_path = "/usr/bin/msmtp -C /etc/msmtprc -a example -t"

With such configuration the email will be sent via SMTP server with authentication, using login and password mysecretpassword.

More information can be found in msmtp manual pages.

Note: Custom php.ini files for customer's wesites can be created only for websites running PHP as FastCGI process. Such php.ini files are created automatically from default php.ini of corresponding PHP handler + custom PHP settings set up in Customer Control Panel.

Search Words

mail forms


send mail from PHP

external SMTP

send email from PHP

php mail function

PHP mail

mail with authorization

PHP forms

auth mail

c1ecc6010feff26cb42d1d14a7881dd6 caea8340e2d186a540518d08602aa065 e0aff7830fa22f92062ee4db78133079 33a70544d00d562bbc5b17762c4ed2b3

Email subscription for changes to this article
Save as PDF