phpemailphpmailermailcatcher

How to send emails to Mailcatcher with PHPMailer?


I have a question which might be a bit stupid, but I can not cope with my problem : I am developing an App where I have to send emails to the users, that's why I am using the PHPMailer library. I tested the application with Google's smtp server and the emails are delivered as expected. Now I installed mailcatcher in order to test my emails locally, but I have no idea how to do it. In the documentation of mailcatcher is written: Send mail through smtp://localhost:1025 How to do this with PHPMailer? Currently I have :

'SMTPDebug'=> 2 ,
'Host' => 'smtp.gmail.com',
'Username'=>'XXXX@gmail.com',
'Password'=>'XXXXXX',
'SMTPSecure'=>'tls',
'Port'=>587,
'From'=> 'test',
'FromName'=> 'test',
'Subject'=>'test',
'IsHTML'=>true

What do I need to change? I tried changng the host to smtp://localhost:1025 , but messages are not delivered. Thank you !


Solution

  • This seems like the most likely 2 things to change

    'SMTPDebug'=> 2 ,
    //'Host' => 'smtp.gmail.com',
    'Host' => '127.0.0.1',
    'Username'=>'XXXX@gmail.com',
    'Password'=>'XXXXXX',
    'SMTPSecure'=>'tls',
    //'Port'=>587,
    'Port'=>1025,
    'From'=> 'test',
    'FromName'=> 'test',
    'Subject'=>'test',
    'IsHTML'=>true
    

    You may also need to remove

    SMTPSecure'=>'tls',
    

    depending on how clever mailcather is