smtp.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. if (!defined('ABSPATH')) exit;
  3. @include_once NEWSLETTER_INCLUDES_DIR . '/controls.php';
  4. $module = Newsletter::instance();
  5. $controls = new NewsletterControls();
  6. if (!$controls->is_action()) {
  7. $controls->data = $module->get_options('smtp');
  8. } else {
  9. if ($controls->is_action('save')) {
  10. if ($controls->data['enabled'] && empty($controls->data['host'])) {
  11. $controls->errors = 'The host must be set to enable the SMTP';
  12. }
  13. if (empty($controls->errors)) {
  14. $module->save_options($controls->data, 'smtp');
  15. $controls->messages .= __('Saved. Remember to test your changes right now!', 'newsletter');
  16. }
  17. }
  18. if ($controls->is_action('test')) {
  19. $mailer = new NewsletterDefaultSMTPMailer($controls->data);
  20. $message = NewsletterMailerAddon::get_test_message($controls->data['test_email']);
  21. $r = $mailer->send($message);
  22. if (is_wp_error($r)) {
  23. $controls->errors = $r->get_error_message();
  24. } else {
  25. $controls->messages = 'Success.';
  26. }
  27. }
  28. }
  29. if (empty($controls->data['enabled']) && !empty($controls->data['host'])) {
  30. $controls->warnings[] = 'SMTP configured but NOT enabled.';
  31. }
  32. ?>
  33. <div class="wrap" id="tnp-wrap">
  34. <?php include NEWSLETTER_DIR . '/tnp-header.php'; ?>
  35. <div id="tnp-heading">
  36. <h2><?php _e('SMTP Settings', 'newsletter') ?></h2>
  37. <p>
  38. <i class="fa fa-info-circle"></i> <a href="https://www.thenewsletterplugin.com/extensions" target="_blank">Discover how SMTP services can boost your newsletters!</a>
  39. <!--
  40. <p>SMTP (Simple Mail Transfer Protocol) refers to external delivery services you can use to send emails.</p>
  41. <p>SMTP services are usually more reliable, secure and spam-aware than the standard delivery method available to your blog.</p>
  42. <p>Even better, using the <a href="https://www.thenewsletterplugin.com/extensions">integration extensions</a>, you can benefit of more efficient service connections, bounce detection and other nice features.</p>
  43. -->
  44. </p>
  45. <p>
  46. <strong>These options can be overridden by extensions which integrates with external
  47. SMTPs (like MailJet, SendGrid, ...) if installed and activated.</strong>
  48. </p>
  49. <p>
  50. What you need to know to use an external SMTP can be found
  51. <a href="https://www.thenewsletterplugin.com/plugins/newsletter/newsletter-configuration#smtp" target="_blank">here</a>.
  52. <br>
  53. On GoDaddy you should follow this <a href="https://www.thenewsletterplugin.com/godaddy-using-smtp-external-server-shared-hosting" target="_blank">special setup</a>.
  54. </p>
  55. <p>
  56. Consider <a href="https://www.thenewsletterplugin.com/affiliate/sendgrid" target="_blank">SendGrid</a> for a serious and reliable SMTP service.
  57. </p>
  58. </div>
  59. <div id="tnp-body">
  60. <form method="post" action="">
  61. <?php $controls->init(); ?>
  62. <table class="form-table">
  63. <tr>
  64. <th>Enable the SMTP?</th>
  65. <td><?php $controls->yesno('enabled'); ?></td>
  66. </tr>
  67. <tr>
  68. <th>SMTP host/port</th>
  69. <td>
  70. host: <?php $controls->text('host', 30); ?>
  71. port: <?php $controls->text('port', 6); ?>
  72. <?php $controls->select('secure', array('' => 'No secure protocol', 'tls' => 'TLS protocol', 'ssl' => 'SSL protocol')); ?>
  73. <p class="description">
  74. Leave port empty for default value (25). To use Gmail try host "smtp.gmail.com" and port "465" and SSL protocol (without quotes).
  75. For GoDaddy use "relay-hosting.secureserver.net".
  76. </p>
  77. </td>
  78. </tr>
  79. <tr>
  80. <th>Authentication</th>
  81. <td>
  82. user: <?php $controls->text('user', 30); ?>
  83. password: <?php $controls->text('pass', 30); ?>
  84. <p class="description">
  85. If authentication is not required, leave "user" field blank.
  86. </p>
  87. </td>
  88. </tr>
  89. <tr>
  90. <th>Insecure SSL Connections</th>
  91. <td>
  92. <?php $controls->yesno('ssl_insecure'); ?> <a href="https://www.thenewsletterplugin.com/?p=21989" target="_blank">Read more</a>.
  93. </td>
  94. </tr>
  95. <tr>
  96. <th>Test email address</th>
  97. <td>
  98. <?php $controls->text_email('test_email', 30); ?>
  99. <?php $controls->button('test', 'Send a test email to this address'); ?>
  100. <p class="description">
  101. If the test reports a "connection failed", review your settings and, if correct, contact
  102. your provider to unlock the connection (if possible).
  103. </p>
  104. </td>
  105. </tr>
  106. </table>
  107. <p>
  108. <?php $controls->button_save(); ?>
  109. </p>
  110. </form>
  111. </div>
  112. <?php include NEWSLETTER_DIR . '/tnp-footer.php'; ?>
  113. </div>