Hej, od kilku dni męczę się z umieszczeniem opcji wysyłania maili na mojej stronce internetowej. Chciałam wykorzystać w tym celu bibliotekę PHPMailer, jednak próbowałam już konfigurować ją na wiele sposobów i niestety nadal bez powodzenia ;< Mam pobraną najnowszą wersję PHPMailer, skonfigurowaną według przykładu na githubie, a mimo to mail nie zostaje wysłany. Dodam jeszcze ze korzystam z Xamppa. Poniżej podaję kod html zakładki kontakt (plik contact.php) wraz z formularzem oraz zawartość pliku mail.php, w którym znajduje się konfiguracja PHPMailer'a. Jeżeli ktoś z Was wie w czym jest problem, albo chociaż ma jakiś pomysł na rozwiązanie to będę baaaardzo wdzięczna z pomoc :)
<script>
document.getElementById("scrollTop").scrollIntoView();
</script>
<?php
require_once "mail.php";
?>
<div id="scrollTop"></div>
<div id="contactContainer">
<h2>Contact Us</h2>
<h4>E-mail:</h4>
<p>[email protected]</p>
<div id="wiadomosci">
<div id="formularz">
<form method="post">
<div class="email_box">
<h3>Enter the e-mail address:</h3>
<input type="text" required name="email" id="email">
</div>
<div class="text_email">
<h3>Enter message:</h3>
<textarea required name="message" id="message" rows="7" cols="50"></textarea>
</div>
<div class="actions">
<input type="submit" value="Send" id="emailSubmitButton" />
<input type="reset" value="Clear" id="clearButton" />
</div>
<p id="response"></p>
</form>
</div>
</div>
</div>
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
if (isset($_POST['submit'])) {
$email = $_POST['email'];
$message = $_POST['message'];
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'password';
$mail->setFrom('[email protected]', 'Mail');
$mail->addAddress('[email protected]');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->IsHTML(true);
$mail->Body = $message;
$mail->AltBody = 'This is a plain-text message body';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}
?>