iamlorddop
@iamlorddop

Почему после сабмита в почте отображает undefined?

При нажатии на кнопку выводится алерт с undefined, как я понимаю не получается найти файли php? Помогите решить вопрос, пожалуйста.

Ошибка в браузере:
63f0b8c3e1048591592624.png

При отправке с сайта, а не с локалхоста:
63f0bebc531cf422123157.png

Для отправки использую PHPMailer

Код php:
spoiler

<?php

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;

    require "./PHPMailer/src/PHPMailer.php";
    require "./PHPMailer/src/Exception.php";
    require "./PHPMailer/src/SMTP.php";

    $mail = new PHPMailer(true);
    $mail->isSMTP(); //Send using SMTP
    $mail->Host = 'smtp.gmail.com';  //Set the SMTP server to send through
    $mail->Username  = 'тут почта//SMTP username
    $mail->Password  = 'тут стоит пароль';  //SMTP password
    $mail->SMTPSecure = "tls";  //Enable implicit TLS encryption
    $mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
    $mail->CharSet = "UTF-8";
    $mail->IsHTML(true);

    $mail->setFrom("тут почта", "Линия доставки");
    // send to
    $mail->addAddress("тут почта", "Линия доставки");

    $theme = '[ДАННЫЕ ИЗ ФОРМЫ ЛИНИЯ ДОСТАВКИ]';
    $mail->Subject = $theme;

    // letter's body
    $body = '<h1>Данные формы:</h1>';

    if(isset($_POST["tel"])){
        $tel = $_POST["tel"];
    }else{
        $tel = "Данные телефона были утерены";
    }

    if (trim(!empty($tel))) {
        $body .= '<p><strong>Телефон:</strong> ' . $tel . '</p>';
    }

    $mail->Body = $body;

    // send
    if (!$mail->send()) {
        $message = 'Ошибка';
    } else {
        $message = 'Данные отправлены!';
    }

    $response = ['message' => $message];

    header('Content-type: application/json');
    echo json_encode($response);

    $mail->smtpClose();
?>



Компонент app.service.ts:
spoiler

import { Injectable } from '@angular/core';
import {HttpClient} from "@angular/common/http";

@Injectable({
  providedIn: 'root'
})
export class AppService {
  constructor(private http: HttpClient) { }
  sendQueryBig (data: any) {
    return this.http.post('http://localhost:4200/send/sendbig.php', data);
  }
  sendQueryMini (data: any) {
    return this.http.post('http://localhost:4200/send/sendmini.php', data);
  }
  sendQuery (data: any) {
    return this.http.post('http://localhost:4200/send/sendtel.php', data);
  }
}



Отправка формы в app.component.ts:
spoiler

submit() {
    if (this.form.valid) {
      console.log(this.form.value)
      this.appService.sendQuery(this.form.value)
        .subscribe(
          {
            next: (response: any) => {
              alert(response.message);
              this.form.reset();
            },
            error: (response) => {
              alert(response.error.message);
            }
          }
        );
    }
  }

  • Вопрос задан
  • 61 просмотр
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы