Answer the question
In order to leave comments, you need to log in
Not sending mail from VPS php?
Previously sat only on shared hosting. Moved to VPS. I am registering with sending a password to the mail.
On hosting in php I used the mail() function. Everything worked great. Now on VPS I tried to do the same.
As expected, nothing came in the mail. There are no errors.
VPS config: nginx, PHP7.2.
Googling the problem, I found a "solution" - using the PHPMailer library in my work.
After struggling, I eventually found how to connect and decided to send a letter.
I wrote the following in the script.
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$mail = new PHPMailer();
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.yandex.ru'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'from'; // SMTP username
$mail->Password = 'parol'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->SMTPDebug = 1;
$mail->Debugoutput = 'html';
//Recipients
$mail->setFrom('[email protected], 'Mailer');
$mail->addAddress('for@mail.ru', 'Joe User'); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question