So I am trying to send mails through PHP, I wrote the code and it works perfectly on local host, however its giving problems on CPanel on deployment. Is there something I am supposed to do seperately on CPanel. Am I missing something? All the necassary files seem to be there on the Cpanel too
Error:
Message could not be sent.Mailer Error: SMTP connect() failed.
<?php
require "PHPMailerAutoload.php";
require "connect.php";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPDebug = false;
$mail->Username =
$mail->Password =
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->From =
$mail->FromName =
if($_POST['type'] == 'Free_Class' ){
// echo !extension_loaded('openssl')?"Not Available":"Available";
$Body ="this is mail from abc for <b>Schedule a Free Class</b><br/>";
$Body .= "Name : ".$_POST['name']."<br/>";
$Body .= "Email : ".$_POST['email']."<br/>";
$Body .= "Mobile : ".$_POST['number']."<br/>";
if(!empty($_POST['course'])){
$Body .= "Course : ".$_POST['course']."<br/>";
}
$subject_text = "Schedule a Free Class";
}
echo $_POST['email'];
echo $_POST['name'];
$mail->AddAddress($_POST['email'],$_POST['name']); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject_text;
$mail->Body = $Body;
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
else{
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$course = $_POST['course'];
$sql = "INSERT INTO demo_class_registrations (name, email, number, course)
VALUES ('$name', '$email', '$number', '$course')";
echo "<script>alert('your response has been recorded. one of our executive contact you soon !!')
window.location.href = '$base_url';
</script>";
}
?>