Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. LAMP
  3. PHPMailer - SMTP Error: Could not connect to SMTP host. STARTTLS command failed Unrecognized command

PHPMailer - SMTP Error: Could not connect to SMTP host. STARTTLS command failed Unrecognized command

Scheduled Pinned Locked Moved LAMP
6 Posts 2 Posters 343 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Laktasekampagne
    wrote on last edited by
    #1

    Hi there,

    I am trying to send a mail via SMTP and PHPMailer.
    The script works fine unless I try to set SMTPSecure to tls. This causes_

    "SMTP Error: Could not connect to SMTP host. STARTTLS command failed Unrecognized command"
    587 is set as port and the outbound relay is looking okay.

    If someone could point me in a good direction, I would be very thankful :).

    Remaining arguments:

    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->Host = getenv('CLOUDRON_MAIL_SMTP_SERVER');
    $mail->SMTPAuth = true;
    $mail->Username = getenv('CLOUDRON_MAIL_SMTP_USERNAME');
    $mail->Password = getenv('CLOUDRON_MAIL_SMTP_PASSWORD');
    $mail->SMTPSecure = '';
    $mail->Port = getenv('CLOUDRON_MAIL_SMTP_PORT');

    $mail->setFrom(getenv('CLOUDRON_MAIL_FROM'), 'Mailer');
    $mail->addReplyTo($email, 'Hello back');
    $mail->addAddress('dummymail@dummy.com', 'Cloudron Test');
    $mail->Subject = 'Hello World';
    $mail->Body = json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
    $mail->CharSet = 'UTF-8';
    $mail->Encoding = 'base64';
    
    1 Reply Last reply
    0
    • J Offline
      J Offline
      joseph
      Staff
      wrote on last edited by
      #2

      @Laktasekampagne does the example at https://docs.cloudron.io/apps/lamp/#email not work?

      1 Reply Last reply
      0
      • J joseph moved this topic from Support on
      • J Offline
        J Offline
        joseph
        Staff
        wrote on last edited by
        #3

        Maybe you can also try $mail->SMTPSecure = false; . Per claude, $mail->SMTPAutoTLS = false; should disable TLS/STARTTLS as well . Can you try adding both ?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Laktasekampagne
          wrote on last edited by
          #4

          Hi Joseph,

          sorry for being unclear here - the mail is being send out if I set $mail->SMTPSecure = ''; like in the example mail at https://docs.cloudron.io/apps/lamp/#email. However, once setting it to $mail->SMTPSecure = 'tls'; I get the error above.

          Will $mail->SMTPSecure = ''; use TLS anyways if the outbound relay is configured to do so?

          J 1 Reply Last reply
          0
          • L Laktasekampagne

            Hi Joseph,

            sorry for being unclear here - the mail is being send out if I set $mail->SMTPSecure = ''; like in the example mail at https://docs.cloudron.io/apps/lamp/#email. However, once setting it to $mail->SMTPSecure = 'tls'; I get the error above.

            Will $mail->SMTPSecure = ''; use TLS anyways if the outbound relay is configured to do so?

            J Offline
            J Offline
            joseph
            Staff
            wrote on last edited by
            #5

            @Laktasekampagne said in PHPMailer - SMTP Error: Could not connect to SMTP host. STARTTLS command failed Unrecognized command:

            Will $mail->SMTPSecure = ''; use TLS anyways if the outbound relay is configured to do so?

            yes, the relay settings are totally different. The PHP code is defining the connection from your app to the cloudron internal mail server . The relay settings is always STARTTLS.

            Also, since the internal mail server is running on the same server as the app, the connection is totally internal to the server. $mail->SMTPSecure = '' is safe.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Laktasekampagne
              wrote on last edited by
              #6

              Thank you Joseph - that helped a lot. Then, everything just works fine :).

              1 Reply Last reply
              1
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Bookmarks
              • Search