PHPMailer и Angular 8 - PullRequest
       6

PHPMailer и Angular 8

1 голос
/ 23 марта 2020

Работа с Angular 8 и PHP (версия 7) и PHPMailer (последняя версия)

Если я введу текст как переменную $, он будет работать нормально. Если я использую Angulars json POST, консоль показывает отправленные данные, но я получаю это сообщение об ошибке:

Неверный адрес: (к): Сообщение не может быть отправлено. Почтовый Ошибка: Неверный адрес: (к):

Любые идеи или мысли очень приветствуются.

Спасибо

<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');


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

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
error_reporting(E_ALL);
//error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
@$subject = $request->subject;
@$sentfrom = $request->sentfrom;
@$sentto = $request->sentto;
@$body = $request->body;
@$cc = $request->cc;
@$bcc = $request->bcc;    
@$attachments = $request->attachments;


$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 = 'MYHOST.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'info@MYHOST.com';                 // SMTP username
    $mail->Password = 'ItsaSecret%#!';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to

    //Recipients

    $mail->addAddress($sentto);

    $mail->setFrom('info@MYHOST.com', '');
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = (string)$subject;
    $mail->Body = (string)$body;
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();

} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
...