Не работает функция php sendmail() на CentOS 6. Дабы не поднимать почтовый сервер, воспользуемся консольным клиентом отправки писем через сервера gmail.
Скачиваем пакет Ssmtp:
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/ssmtp-2.61-22.el6.x86_64.rpm |
Устанавливаем:
rpm -ivh ssmtp-2.61-22.el6.x86_64.rpm |
Правим конфиг ssmtp:
nano /etc/ssmtp/ssmtp.conf |
ssmtp.conf:
# # /etc/ssmtp.conf -- a config file for sSMTP sendmail. # # See the ssmtp.conf(5) man page for a more verbose explanation of the # available options. # # The person who gets all mail for userids < 500 # Make this empty to disable rewriting. root=mygooglemail@gmail.com # The place where the mail goes. The actual machine name is required # no MX records are consulted. Commonly mailhosts are named mail.domain.com # The example will fit if you are in domain.com and your mailhub is so named. mailhub=smtp.gmail.com:587 # Example for SMTP port number 2525 # mailhub=mail.your.domain:2525 # Example for SMTP port number 25 (Standard/RFC) # mailhub=mail.your.domain # Example for SSL encrypted connection # mailhub=mail.your.domain:465 AuthUser=slavanchik@gmail.com AuthPass=gmailpassword # Where will the mail seem to come from? #RewriteDomain=gmail.com # The full hostname Hostname=localhost # Set this to never rewrite the "From:" line (unless not given) and to # use that address in the "from line" of the envelope. FromLineOverride=YES # Use SSL/TLS to send secure messages to server. #UseTLS=YES UseTLS=YES UseSTARTTLS=YES AuthMethod=LOGIN # Use SSL/TLS certificate to authenticate against smtp host. #UseTLSCert=YES # Use this RSA certificate. #TLSCert=/etc/pki/tls/private/ssmtp.pem TLSCert=/etc/pki/tls/certs/ca-bundle.crt TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt # Get enhanced (*really* enhanced) debugging information in the logs # If you want to have debugging of the config file parsing, move this option # to the top of the config file and uncomment #Debug=YES |
Правим алиасы ssmtp:
nano /etc/ssmtp/revaliases |
/etc/ssmtp/revaliases:
# sSMTP aliases # # Format: local_account:outgoing_address:mailhub # # Example: root:your_login@your.domain:mailhub.your.domain[:port] # where [:port] is an optional port number that defaults to 25. root:mygooglemail@gmail.com:smtp.gmail.com:587 |
Пробуем отправить сообщение из консоли средствами ssmtp:
echo "hi" | ssmtp -v -s Hello mail_to_send@mail.ru |
Если сообщение не пришло, смотрим еще раз более внимательно конфиг и алиасы.
У нас письмо пришло. Настало время заменить встроенный sendmail нашим клиентом ssmtp.
Бэкапим sendmail:
mv /usr/sbin/sendmail /usr/sbin/sendmail.old |
Создаем симлинк:
ln -s /usr/sbin/ssmtp /usr/sbin/sendmail |
На этом всё. Функция php sendmail() прекрасно работает через сервера gmail и писма приходят с нашей гугловской почты.