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!

+3


source to share


4 answers


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.

-2


source


Just a comment $mail->IsSMTP();

.. I had the same problem. It didn't work on the local host and on the live server. After I commented $mail->IsSMTP();

it works fine ... Hopefully this might be helpful for u, this.



+16


source


If you uninstall $mail->IsSMTP()

, you will NOT use SMTP

! PHPMailer will then use the built-in function mail()

and all your special settings SMTP

will be ignored!

+2


source


As vani suggested, I removed the line $mail->IsSMTP();

AND it worked for me on the server, but not in xampp, in xampp you need to save it.

-2


source







All Articles