@vahan21

PHPMailer error не работает?

Здравствуйте.

Подскажите, пожалуйста, в чём проблема?

Выдаёт error :)

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

// Load Composer's autoloader
require 'vendor/autoload.php';

// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
    if (isset($_POST['send'])) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $subject = $_POST['subject'];
        $message = $_POST['message'];
        //Server settings
        $mail->SMTPDebug = 1;     
        $mail->isSMTP(); 
        $mail->Host       = 'smtp.sendgrid.net';
        $mail->SMTPAuth   = true;  
        $mail->Username   = 'vahan'; 
        $mail->Password   = 'va551155+'; 
        $mail->SMTPSecure = 'tls';
        $mail->Port       = 587;   
        //Recipients
        $mail->setFrom('vahan_12@gmail.com', 'Mailer');
        $mail->addAddress('vahanbarseghyan21@gmail.com');  
        // Content
        $mail->isHTML(true);  
        $mail->Subject = $subject;
        $mail->Body    = $message;
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

        $mail->send();
        echo 'Message has been sent';
    }
    else{
        echo "error :)";
    }
}
catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
  • Вопрос задан
  • 225 просмотров
Решения вопроса 1
glaphire
@glaphire Куратор тега PHP
PHP developer
Дословно по коду:
if (isset($_POST['send'])) {
      ...
} else {
    echo "error :)";
}

Значит внутри $_POST нет элемента с ключем send.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
YCLIENTS Москва
от 200 000 до 350 000 ₽
Ведисофт Екатеринбург
от 25 000 ₽
от 300 000 до 500 000 ₽
07 мая 2024, в 18:23
20000 руб./за проект
07 мая 2024, в 18:09
2000 руб./за проект
07 мая 2024, в 17:40
300 руб./за проект