Wrzuciłem na stronę phpMailer w najnowszej wersji z githuba, skrypt wysyła emaile ale mam jedno pytanie:
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; date_default_timezone_set('Etc/UTC'); require './PHPMailer/PHPMailer/src/PHPMailer.php'; require './PHPMailer/PHPMailer/src/SMTP.php'; require './PHPMailer/PHPMailer/src/Exception.php'; // Fetching Values from URL. $email = $_POST['email1']; $email = filter_var($email, FILTER_SANITIZE_EMAIL); if (filter_var($email, FILTER_VALIDATE_EMAIL)) { $mail = new PHPMailer(true); $mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output $mail->isSMTP(); // Send using SMTP $mail->CharSet = 'utf-8'; $mail->setLanguage('pl'); $mail->Host = 'moj_smtp'; // Set the SMTP server to send through $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'moj_adres'; // SMTP username $mail->Password = 'moje_haslo'; // SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged $mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above $mail->setFrom('moj_adres', 'moja_nazwa'); $mail->addAddress('adres_adresata'); // Add a recipient $mail->addReplyTo('moj_adres', 'moja_nazwa'); $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Tytul emaila'; $mail->Body = 'Treśc emaila'; $mail->Send(); if($send){ $dane_post = []; $dane_post['info'] = "Twoja wiadomość została wysłana, odpowiemy najszybciej, jak się da;)"; }else{ $dane_post = []; $dane_post['error'] = 'E-mail nie mógł zostać wysłany, przyczyna :'. $mail->ErrorInfo; } } }
Dlaczego nie da się przypisać danych do tablicy $dane_post?
Jak wkleję ten kod przed $mail->Send() to się ładnie dodadzą dane do tablicy- ale wtedy nie wiem czy się email wysłała czy nie, co może przeszkadzać?