0

Edit: Jawish has explained why a blank page occurs when submitting my code. I simply forgot an echo statement. This has been marked as the correct answer even though it hasn't gotten my code to successfully run. My question was vague and Jawish found an issue that will help me with error reporting. I'll post another edit if I can find the issue with the code.


I'm having a small problem sending information using the following code to login to my gmail account. As soon as I run my form and submit it, I'm just shown a blank page. I've attempted to find some kind of error, but I can't get the error to display. I've followed the answer from this post, but even making those changes and adding the code does nothing that I can tell. This code is supposed to run the mailer and once the email is sent, the user is supposed to be redirected to a 'thank you' page with never happens. So the issue happens in one of the two codes listed. The strange thing is this use to work. I went on vacation then came back and now it doesn't work. I'm sure I messed something up somehow, but I'm at a loss for ideas.

Any help is appreciated, thanks. (asterisks are shown to hide personal information)

<?php

session_start();

require_once '../PHPMailer-master/PHPMailerAutoload.php';

if(isset($_POST['icon'])){


    $m = new PHPMailer();
    $m->isSMTP();
    $m->SMTPAuth = true;

    $m->Host = 'smtp.gmail.com';
    $m->Username = '*********@gmail.com';
    $m->Password = '****';
    $m->SMTPSecure = 'ssl';
    $m->Port = 465;

    $m->isHTML(true);

    $m->Subject = 'Contact form submitted';
    $m->Body = $_POST['icon'];

    $m->FromName = 'Contact';

    $m->AddAddress('********@gmail.com','***Name Here****');

    if($m->send()) {
        header('Location: contact_thanks.php');
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $m->ErrorInfo;
        die();  
    } else {
        'Sorry, could not send email';
    }

} else {'something went wrong';}

?>

This is the PHPMailerAutoload.php referenced in the previous code.

<?php

function PHPMailerAutoload($classname)
{
    //Can't use __DIR__ as it's only in PHP 5.3+
    $filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
    if (is_readable($filename)) {
        require $filename;
    }
}

if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
    //SPL autoloading was introduced in PHP 5.1.2
    if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
        spl_autoload_register('PHPMailerAutoload', true, true);
    } else {
        spl_autoload_register('PHPMailerAutoload');
    }
} else {
    /**
     * Fall back to traditional autoload for old PHP versions
     * @param string $classname The name of the class to load
     */
    function __autoload($classname)
    {
        PHPMailerAutoload($classname);
    }
}
?>
Community
  • 1
  • 1
Pat
  • 63
  • 7

1 Answers1

1

You are missing "echo" statements on the last else blocks so you would not get any output on those branches.

Should be:

    } else {
        echo 'Sorry, could not send email';
    }

} else {
    echo 'something went wrong';
}
jawish
  • 486
  • 2
  • 4
  • Brilliant, thank you. Not sure how I didn't see that. It now echoes 'something went wrong'. I'll try to run some error reporting again. – Pat Jul 27 '15 at 14:50