I'm trying to send an email with SMTP in php for my contact us section but whatever i do it just doesn't work. I did exactly what i read in https://github.com/PHPMailer/PHPMailer . please tell me where i'm going wrong? here is my code:
include_once 'model/Mcont.php';
require 'public/include/PHPMailer.php';
$mail = new PHPMailer();
if(isset($_POST['btn-contact'])){
if(empty($_POST['text']) || empty($_POST['email']) || empty($_POST['text'])){
header("location:http://website.com/?c=cont&warning=e");
}else{
$email = $_POST['email'];
$userName = $_POST['username'];
$text = $_POST['text'];
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'mail.example.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'username'; //SMTP username
$mail->Password = 'password'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable implicit TLS encryption
$mail->Port = 587; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom($email, $userName);
$mail->addAddress('info@example.com', 'me'); //Add a recipient
$mail->addReplyTo($email, 'reply');
$mail->addCC('info@example.com');
$mail->addBCC('info@example.com');
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'ARTALEF WEBSITE';
$mail->Body = $text.'<br>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
header("location:http://website.com/?c=cont&s=em_s");
}
}
include_once 'view/cont/cont.php';
?>
source https://stackoverflow.com/questions/68145366/how-to-send-an-email-with-smtp-in-php
Comments
Post a Comment