Question

PHPmailer stopped working

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. :(

<?php

/*
 * 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
    )
);
$mail->smtpConnect($options);
//Tell PHPMailer to use SMTP
$mail->isSMTP();

//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->addAddress('info@rederijwolthuis.nl');

        $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>
            <?php
        }

        else

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


        }

#bertvanhouten@icloud.com
#info@rederijwolthuis.nl
?>


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Insecure apps are premitted. Thanks for the link.

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