PHPMailer works on localhost but on but not on server

user3340031 picture user3340031 · Jan 5, 2015 · Viewed 16.1k times · Source

I'm trying to send a mail that is contents.html to some person, this code works fine on XAMPP but doesn't work on server, just shows empty screen and ends up without sending 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)."[email protected]";
    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("[email protected]");
    $mail->Subject = "Student Feedback ".$branch . " ".$yearandsem;
    $mail->Body = "hello, Here's 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"');
}
?>

the displaygraphs is working fine, after I tested with some echo's, I came to know that the page is stopping after the line $mail = new PHPMailer(); line in gmail.php, please help me solve this, Thank You!

Answer

vani picture vani · Jan 8, 2015

Just comment $mail->IsSMTP(); ..I had same problem..On localhost its working and on live server not working..After I commented $mail->IsSMTP(); this, Its working fine..Hopes so might be helpful for u it is.