D
D
Dmitry Tarasov2018-04-25 14:43:08
SMTP
Dmitry Tarasov, 2018-04-25 14:43:08

Why doesn't phpmailer send a message via smtp?

I send a message, the code is below

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'mail.profitway.net';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '[email protected]';                 // SMTP username
    $mail->Password = 'none';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('[email protected]', 'Mailer');
    $mail->addAddress('[email protected]', '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();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo $e->getMessage();
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

The following error is shown

2018-04-25 11:33:54 SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubl...
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubl... could not be sent. Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubl...

then we put
$mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    );

After adding this code, everything starts working, but it ends up in the spam folder.
I understand that the problem is with certificates, but I don’t know what the problem is and how to fix it. The SSL certificate is free, I added mail through isp manager, I took access accordingly from there, host, port, etc. Why doesn't it send without these settings?
$mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    );

Please help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2018-04-25
@LiguidCool

As an option: SPF , DKIM
You want to put a certificate for client authorization, and the problem seems to be that your server is not trusted by other servers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question