PHPMailer runs on localhost but not server
I am trying to send an email that is .html content to someone, this code works fine on XAMPP but does not work on the server, it just shows a blank screen and ends without sending any mail. What am I doing wrong?
gmail.php
<?php
include('/mailer/class.phpmailer.php');
include('/mailer/class.smtp.php'); // optional, gets called from within class.phpmailer.php if not already loaded
$hodemail = strtolower($branch)."hodofsrit@gmail.com";
echo '1';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
echo '2';
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "xxxxxxxxxx";
$mail->Password = "xxxxxxxx";
$mail->SetFrom("134g1a05a1@srit.ac.in");
$mail->Subject = "Student Feedback ".$branch . " ".$yearandsem;
$mail->Body = "hello, Here the graph generated";
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
$mail->AddAddress($hodemail);
if(!$mail->Send())
{
$error = $mail->ErrorInfo;
header('Location:sendmail.php?errormsg=There was an error in sending email '.$error);
}
else
{
function redirect($url)
{
$string = '<script type="text/javascript">';
$string .= 'window.location = "' . $url . '"';
$string .= '</script>';
echo $string;
}
redirect('sendmail.php?msg=Email Successfully sent to corresponding HOD!');
}
?>
send_mail.pgp
<?php
session_start();
if(isset($_SESSION['admin'])){
$branch = $_POST['branch'];
$yearandsem = $_POST['yearandsem'];
include 'displaygraphs.php';
include'gmail.php';
}
else {
header('location:index.php?msg="Login First"');
}
?>
displaygraphs works fine, after I tested a few echo's
, I found out that the page stops after a line $mail = new PHPMailer();
in gmail.php, please help me to solve this, thanks!
If this fails new PHPMailer()
, the library may not load. Check the path to your mail program directory, which looks like this:
/mysrit/mailer/class.phpmailer.php
(note the start / absolute value)
or
mailer/class.phpmailer.php
(note the lack of start / path selection).
I would suggest making a library required . I.e:
require 'mailer/class.phpmailer.php';
or if it can load multiple times:
require_once 'mailer/class.phpmailer.php';
Thus, the script will stop executing immediately when it cannot find the mailer library.
source to share