





от: lenta 2020-10-14 13:42:02
mail() php linux msmtp
[700]
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 = "<html><head><title>$title</title></head><body>$body</body></html>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: YOU_NAME <YOU_ACCOUNT@yandex.ru>' . "\r\n";
$result = mail($email, $title, $body, $headers);
if($result){
echo 'send true';
} else {
echo 'send false';
}
если же вы настроили на своём сервере dovecot + postfix, то в php.ini можно записать:
sendmail_path = /usr/sbin/sendmail -t -i -fno-reply@example.com
[700]

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 = "<html><head><title>$title</title></head><body>$body</body></html>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: YOU_NAME <YOU_ACCOUNT@yandex.ru>' . "\r\n";
$result = mail($email, $title, $body, $headers);
if($result){
echo 'send true';
} else {
echo 'send false';
}
если же вы настроили на своём сервере dovecot + postfix, то в php.ini можно записать:
sendmail_path = /usr/sbin/sendmail -t -i -fno-reply@example.com