[инфа]

от: lenta 2020-10-14 13:42:02

mail() php linux msmtp
[просмотров|25] linux
1. aptitude install msmtp

2. touch /etc/msmtprc

3. chmod 600 /etc/msmtprc

4. chown www-data:www-data /etc/msmtprc

5. nano /etc/msmtprc

defaults
tls on
auth on
tls_starttls on
tls_certcheck off
logfile /var/log/msmtp.log
timeout 20

account yandex
logfile /var/log/msmtp.log
host smtp.yandex.ru
port 587
from YOU_ACCOUNT@yandex.ru
keepbcc on
auth on
user YOU_ACCOUNT@yandex.ru
password YOU_PASSWORD
tls on
tls_starttls on

account default : yandex


6. php.ini

;SMTP = localhost
;smtp_port = 25
sendmail_path = "/usr/bin/msmtp -t"

service apache2 restart or service php-fpm restart

7. test.php

$email = 'test@yandex.ru';
$title = 'test title';
$body = 'test body';

$body = "$title$body";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: YOU_NAME ' . "\r\n";

$result = mail($email, $title, $body, $headers);
if($result){
echo 'send true';
} else {
echo 'send false';
}


fizord.ru © 2020
Андрей Исаков