Search code examples
xamppwindowphpmailer

PHPMailer not running with Xampp on Windows10


my problem is that PHPMailer (PHPMailer-master 6.0.3 to be exact) does not deliver emails when I run it with Xampp and Windows10. (I found a lot of comments on that subject but none of them led to a solution.)

The following code runs fine on a remote server:

 <?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;


// 'PHPMailer' here actually is the original folder 'PHPMailer-master' 
// from unpacking the downloaded file PHPMailer-master.zip
require 'vendor/PHPMailer/src/Exception.php';
require 'vendor/PHPMailer/src/PHPMailer.php';
require 'vendor/PHPMailer/src/SMTP.php';

echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."\n"; 

$mail = new PHPMailer(true);         // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;            // Enable verbose debug output

    $mail->$mail->isSendmail();     // corrected 
    $mail->Host = 'smtp.kabelmail.de';          //smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                 // Enable SMTP authentication
    $mail->Username = '[email protected]';     // SMTP username
    $mail->Password = 'mypassword';              // SMTP password
    $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                           // TCP port to connect to

    //Recipients
    $mail->setFrom('[email protected]', 'Mailer');
    $mail->addAddress('[email protected]', 'myname');  // Add a recipient
    // $mail->addAddress('[email protected]');           // Name is optional
    $mail->addReplyTo('[email protected]', 'Antwort');
    //$mail->addCC('[email protected]');
    //$mail->addBCC('[email protected]');

    //Attachments
    //$mail->addAttachment('/var/tmp/file.tar.gz');     // Add attachments
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    //Content
    $mail->isHTML(true);                        // Set email format to HTML
    $mail->Subject = 'Here is the subject:localhost';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = ' body in plain text for non-HTML mail lients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>

I left the script above as it is and modified php.ini for Xampp in accordance with the comments at Phpmailer not working running from localhost (XAMPP):

[mail function]
SMTP=smtp.kabelmail.de
smtp_port=465
sendmail_from = [email protected]
sendmail_path ="C:\xampp\sendmail\sendmail.exe\"
;(I also tried sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" but without success.)
mail.log="C:\xampp\php\logs\php_mail.log"

These are the modifications to sendmail.ini:

[sendmail]
smtp_server=smtp.kabelmail.de
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=mypassword

Results: 1. With the settings above I got this message:

SSL loaded 2018-01-11 12:06:10 SERVER -> CLIENT: 421 4.3.2 Too many open connections.
2018-01-11 12:06:10 CLIENT -> SERVER: EHLO localhost
2018-01-11 12:06:10 SERVER -> CLIENT: 
2018-01-11 12:06:10 SMTP ERROR: EHLO command failed: 
2018-01-11 12:06:10 SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not connect to SMTP host.
SMTP Error: Could not connect to SMTP host.
Message could not be sent.Mailer Error: SMTP Error: Could not connect to SMTP host.
  1. I then replaced $mail->isSendmail(); by $mail->isMail(); The message that showed up now was SSL loaded Message has been sent

That is what I was looking for, but - there was no message in the mailbox.!!! php_mail.log had this information, which doesn't look suspicious to me:

    [11-Jan-2018 13:09:32 Europe/Berlin] mail() on [C:\xampp\htdocs\to\vendor\PHPMailer\src\PHPMailer.php:768]: To: "name" <[email protected]> -- Headers: Date: Thu, 11 Jan 2018 13:09:32 +0100  From: Mailer <[email protected]>  Reply-To: Antwort <[email protected]>  Message-ID: <VuAQ3BR022MQyNd3hKCoguqr50Ry9TPG4vIRL2ZmFg@localhost>  X-Mailer: PHPMailer 6.0.3 (https://github.com/PHPMailer/PHPMailer)  MIME-Version: 1.0  Content-Type: multipart/alternative;     boundary="b1_VuAQ3BR022MQyNd3hKCoguqr50Ry9TPG4vIRL2ZmFg"  Content-Transfer-Encoding: 8bit

Can somebody give me a hint what might be wrong? I have been working on that for several days now but obviously I am missing something basic.

--- Edit Jan. 12, 2018 -------------------------------------------------

$mail->isSendmail(); is the setting that is ok on the remote server!


Solution

  • Solved.

    The breakthrough was reached when I moved to smtp.web.de.

    I now get the the messages from client and server ($mail->SMTPDebug = 2;).

    The server still complained about

    $mail->setFrom('[email protected]', 'Mailer');
    

    saying

    "MAIL FROM command failed: 550-Requested action not taken: mailbox unavailable550 Sender address is not allowed".

    Replacing it by

    $mail->setFrom('[email protected]', 'via web.de');
    

    did the job. But not all servers complain about that. Dogado.de for instance does not.

    Finally:

    $mail->SMTPDebug = 0;     // suppresses server and client messages for production use
    $mail->CharSet = "UTF-8";  // for correct umlauts
    

    Summary:

    The following code can be used on a local machine (Xampp, Netbeans) as well as on a remote server.

    <?php
    // Import PHPMailer classes into the global namespace
    // These must be at the top of your script, not inside a function
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    
    // adjust path accordingly!
    require 'vendor/PHPMailer/src/Exception.php';
    require 'vendor/PHPMailer/src/PHPMailer.php';
    require 'vendor/PHPMailer/src/SMTP.php';
    
    
    // is ssl loaded? (test only):
    //echo (extension_loaded('openssl')?'SSL loaded, ':'SSL not loaded, ')."\n"; 
    
    $mail = new PHPMailer(true);             // Passing `true` enables exceptions
    try {
        $mail->SMTPDebug = 0;   // production use
        $mail->isSMTP();            // Set mailer to use SMTP
    
        //=== using web.de ========================================
        // adjust settings to your project!
        $mail->Host = 'smtp.web.de';             //smtp1.example.com;smtp2.example.com';  
                                                 // Specify main and backup SMTP servers
        $mail->Username = '[email protected]';       // SMTP username   
        $mail->Port = 587;                       // TCP port to connect to
        $mail->setFrom('[email protected]', 'über web.de'); // required by web.de
        $mail->Password = 'mypassword';          // SMTP password
        //==========================================================
        $mail->SMTPAuth = true;                  // Enable SMTP authentication
        $mail->SMTPSecure = 'tls';          // Enable TLS encryption, `ssl` also accepted
    
        //Recipients
        $mail->addAddress('[email protected]', 'my name'); // Add a recipient
        $mail->addAddress('[email protected]');                // Name is optional
        $mail->CharSet = "UTF-8";               // because of umlauts
    
        //$mail->addCC('[email protected]');
        //$mail->addBCC('[email protected]');
    
        //Attachments
        //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
        //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
    
        //Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = 'Here is the subject';
        $mail->Body    = 'This is the HTML message body <b>in bold! groß süß ähnlich Ökonom</b>';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients: groß süß ähnlich Ökonom';
    
        $mail->send();
        echo 'Message has been sent';
    } catch (Exception $e) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    }