S
S
SKEPTIC2020-01-05 18:31:46
PHP
SKEPTIC, 2020-01-05 18:31:46

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();

Instead of the required fields by type: sender, SMTP login and SMTP password, I substituted the correct values.
But unfortunately the solution doesn't work. In fact, it doesn't even finish the job. When refreshing the page, I expected to see at least some errors. But in the end, I saw nothing but an endlessly loading page.
How to solve this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2020-01-05
@dimonchik2013

SMTP logs
outgoing resolved?

R
Randewoo, 2020-01-05
@Randewoo

The single quote is missing:
$mail->setFrom('[email protected],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question