isSMTP(); //Send using SMTP
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$mail->Username = 'harishdholplayer1@gmail.com'; //SMTP username
$mail->Password = 'sqeiwdfiqmygjulj'; //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('harishdholplayer1@gmail.com', 'Harish Dhol Wala');
$mail->addAddress('harishdholplayer1@gmail.com', 'User'); //Add a recipient
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'User Enquiry';
$mail->Body = "
User Name : $name
Phone Number : $phone
Email Id : $email
Subject : $subject_message
Message : $message
";
if($mail->send()){
$_SESSION['status'] = "Thank you for sending mail";
header("Location: {$_SERVER['HTTP_REFERER']}");
exit(0);
}else{
$_SESSION['status'] = "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
header("Location: {$_SERVER['HTTP_REFERER']}");
exit(0);
}
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}else{
header("Location: {$_SERVER['HTTP_REFERER']}");
}
?>