PHPmailer stopped working

August 23, 2016 244 views
PHP Apache Ubuntu

My PHPmailer script on one of my websites is failing silently. I produces no errors and redirects to the succes page. I'm using a gmail-account that sends the emails for me but it does not show any send mails. this setup has worked in the past but just stop working. I have updated some of the programs on my server, but fail to see how that should produce this problem. Im using the same gmail account and same script from a other website hosted somewhere else and that one works. I have already updated PHPmailer to the latest version but no luck. Out of ideas. :(


 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
    require_once dirname(__FILE__).'/vendor/PHPMailerAutoload.php';

    //require_once dirname(__FILE__).'/vendor/class.smtp.php';

    if( isset( $_POST ) ){

        $date              = $_POST['date'];
        $name              = $_POST['naam'];
        $aantal_personen   = $_POST['aantal_personen'];
        $email             = $_POST['email'];
        $telefoonnummer    = $_POST['telefoonnummer'];
        $extra             = $_POST['extra'];

        $message .= "<p>Naam van groep: {$name}</p>";
        $message .= "<p>Aantal personen: {$aantal_personen}</p>";
        $message .= "<p>Datum van vaart: {$date}</p>";
        $message .= "<p>e-mail: {$email}</p>";
        $message .= "<p>Telefoonnummer: {$telefoonnummer}</p>";
        $message .= "<p>Extra info: {$extra}</p>";

        $mail = new PHPMailer(true);

       $options = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
//Tell PHPMailer to use SMTP

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;

//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';

//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "pannenkoekenbootdenbosch@gmail.com";

//Password to use for SMTP authentication
$mail->Password = "password";

        #$mail->FromName = ;

        //Naar wie moet de mail gestuurd worden

        $mail->addReplyTo( $email );

        $mail->setFrom('info@rederijwolthuis.nl','Rederij Wolthuis');

        $mail->isHTML( true );
        $mail->Subject = "Reservering Pannenkoekenboot op {$date} naam: {$name}";
        $mail->Body= $message;

        if( !$mail->send() ){
                <div class='niet_verzonden'>Er is een fout opgetreden met het versturen van uw boeking.</div>
                <div class='error'><? echo $mail->ErrorInfo; ?></div>


            header("Location: http://www.pannenkoekenbootdenbosch.nl/boeking-bevestiging.html");



2 Answers

it is possible to setup postfix to use your gmail account, but even if you do not want to do that browse this article: https://www.howtoforge.com/tutorial/configure-postfix-to-use-gmail-as-a-mail-relay/

..note the settings you want to do in gmail to allow insecure apps. It is a possible culprit

Insecure apps are premitted. Thanks for the link.

Have another answer? Share your knowledge.