V
V
Vladislav Argun2021-04-09 21:49:18
PHPMailer
Vladislav Argun, 2021-04-09 21:49:18

Why is a message not sent to the mail through phpmailer?

I started sending data to the mail through phpmailer. But it didn't work, there are no errors, the page loads endlessly. Why is a message not sent to the mail through phpmailer?

<?php
    if(isset($_POST['submit'])){
        require_once('dbconnect.php');
        ini_set('display_errors',1);
        error_reporting(E_ALL);
        mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
        require './phpmailer/PHPMailerAutoload.php';
        $name = $_POST['name'];
        $email = $_POST['email'];
        $tel = $_POST['number'];
        $sum = $_POST['sum'];
        $date = $_POST['date'];
        $selected_id = $_COOKIE['selected_id'];
        $a = "date: ".$date."   sum: ".$sum."   Name: ".$name."   E-Mail: ".$email."   tel: ".$tel." ";
        $message = "Здравствуйте. Вы отправили данные заказчику, он просмотрит ваше предложение и ответит вам!";
        $message2 = "Здравствуйте. Пришло новое предложение от: ".$name.". Вы можете рассмотреть его, и связаться с нами по телефону +7999999999";
        $select = "SELECT email FROM cards WHERE id=".$_COOKIE['selected_id'];
        $email2 = mysqli_query($link, $select);
        $result = "INSERT INTO zakaz (name, sum, tel, email, `date`, selected_id) VALUES ('$name', '$sum', '$tel', '$email', '$date', '$selected_id')";


        // MAIL ОТПРАВКА
        
        $mail = new PHPMailer;
    
    //$mail->SMTPDebug = 3;                               // Enable verbose debug output
    
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.mail.ru';  // 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 = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 993;                                    // TCP port to connect to
    
    $mail->setFrom('[email protected]', '[email protected]');
    $mail->addAddress($email);     // Add a recipient
    // $mail->addAddress($email2);               // Name is optional
    // $mail->addReplyTo('[email protected]', 'Information');
    // $mail->addCC('[email protected]');
    // $mail->addBCC('[email protected]');
    
    // $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    // $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
    $mail->isHTML(true);                                  // Set email format to HTML
    
    $mail->Subject = 'Work Abkhazia';
    $mail->Body = $message;
    // $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    // mail($email, "Work Abkhazia", $message);
    // $mail->addAddress($email2);
    // mail($email2, "Work Abkhazia", $message2, $headers);
        if ($link->query($result)){
            mail($email, 'Mail: work.abkhazia.tilda.ws', $message);
            // header('Location: /');
        } else {
           die('Ошибка: '.mysqli_error());
        };
    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    };
    };
?>
<link rel="stylesheet" type="text/css" href="./css/black.css">

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-04-09
@galaxy

$mail->Port = 993;
993 is the port for IMAP
For SMTP they have 465

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question