Hello I'm trying to create a way to send auto emails on my website. I'm using phpmailermaster for this. to test the mailing out I created a button that when pressed should send an email to the email I have written in there. but I can't seem to get it to work? what am I doing wrong?? it continue to give me "kan geen mail versturen" this means in english "can't send a mail"
I tried to do an error check and I get this error:
Message could not be sent.Mailer Error: SMTP connect() failed.
mailen.php
<?php
use PHPMailer\PHPMailer\PHPMailer;
require 'PHPMailer.php';
require 'SMTP.php';
require 'Exception.php';
function mailen($ontvangerStraat = null, $ontvangerNaam = null, $onderwerp = null, $bericht = null) {
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "schoolrebecca98@gmail.com";
$mail->Password = "xxxx";
$mail->isHTML(true);
$mail->From = 'schoolrebecca98@gmail.com';
$mail->FromName = 'Naam';
$mail->Subject = $onderwerp;
$mail->CharSet = 'UTF-8';
$bericht = "<body style=\"font-family: Verdana, Verdana, Geneva, sans-serif; font-size: 14px; color: #000;\">". $bericht . "</body></html>";
$mail->AddAddress($ontvangerStraat, $ontvangerNaam);
$mail->Body = $bericht;
if($mail->Send()){
echo "<script>alert('Mail is verstuurd');</script>";
}else{
echo "<script>alert('Kon geen mail versturen');</script>";
}
}
?>
the mail structure
<?php include "mailen.php";?>
<html>
<!-- sending a mail -->
<body>
<?php
$newtime = date('H:i', time() + 3600);
$email = "schoolrebecca98@gmail.com";
$klant = "test";
$onderwerp = "Bestelling";
$bericht = "Geachte $klant, uw bestelling is bevestigd! U kunt uw order ophalen om $newtime";
mailen($email, $klant, $onderwerp, $bericht);
?>
</body>
</html>
the button that should send this mail however this doesn't work
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<button type="button" class="btn btn-primary"><a href="mail/bevestigordermail.php">sent mail</a></button>
What I have tried:
I have a book with a tutorial on how to do php mailer master but I can't get it to work nor do I see what I'm doing wrong. Tried looking it up on the internet but this also gave me no results. it does seem to be a common problem