The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Debugging email setup
#1
I was having difficulty figuring out what was wrong with my email configuration. Everything seemed fine, but I kept getting the (someone unhelpful) "Email ERROR" message whenever I tried to test my email setup.

I modified the email setup test to allow for setting a debug level and then modified the helpers.php so that it would respond to the presence of $_POST['SMTPDebug'] to turn on debugging.

NOTE: This should *not* be turned on in a development environment! It opens significant security holes. But if you are struggling with an email configuration problem it can be invaluable for you...

(The checkbox to turn on the exceptions looks kind of gross - I'm still trying to figure out how to style things nicely within this framework...)

Here's the patch file:

diff -bcr ../UserSpice41/users/email_test.php ./users/email_test.php
*** ../UserSpice41/users/email_test.php 2016-08-15 15:51:50.062520500 +0200
--- ./users/email_test.php 2016-08-23 18:35:35.767763900 +0200
***************
*** 27,46 ****
Redirect::to('account.php');
}
?>
- <?php
- //PHP Goes Here!
-
- $query = $db->query("SELECT * FROM email");
- $results = $query->first();
-
- if(!empty($_POST)){
- $to = $_POST['test_acct'];
- $subject = 'Testing Your Email Settings!';
- $body = 'This is the body of your test email';
- $mail_result=email($to,$subject,$body);
- }
-
- ?>
<div id="page-wrapper">

<div class="container-fluid">
--- 27,32 ----
***************
*** 61,79 ****
It's a good idea to test to make sure you can actually receive system emails before forcing your users to verify theirs. <br><br>
<?php
if (!empty($_POST)){
if($mail_result){
echo 'Mail sent successfully<br/>';
}else{
echo 'Mail ERROR<br/>';
}
-
}
-
?>

<form class="" name="test_email" action="email_test.php" method="post">
<label>Send test to (Ideally different than your from address):
<input required size='50' class='form-control' type='text' name='test_acct' value='' /></label>

<label> </label>
<input class='btn btn-primary' type='submit' value='Send A Test Email' class='submit' />
--- 47,85 ----
It's a good idea to test to make sure you can actually receive system emails before forcing your users to verify theirs. <br><br>
<?php
if (!empty($_POST)){
+ /* these appear to be unused
+ $query = $db->query("SELECT * FROM email");
+ $results = $query->first();
+ */
+
+ $to = $_POST['test_acct'];
+ $subject = 'Testing Your Email Settings!';
+ $body = 'This is the body of your test email';
+ $mail_result=email($to,$subject,$body);
+
+ if (isset($_POST['SMTPDebug']))
+ echo "<br />\n";
if($mail_result){
echo 'Mail sent successfully<br/>';
}else{
echo 'Mail ERROR<br/>';
}
}
?>

<form class="" name="test_email" action="email_test.php" method="post">
<label>Send test to (Ideally different than your from address):
<input required size='50' class='form-control' type='text' name='test_acct' value='' /></label>
+ <label><input class='form-control' type="checkbox" name="PHPMailerExceptions" />Report Exceptions</label>
+ <label>Debug Level:
+ <select class='form-control' name="SMTPDebug">
+ <option value=0 selected="selected">Debugging OFF</option>
+ <option value=1>Client</option>
+ <option value=2>Client + Server</option>
+ <option value=3>Client + Server + Connection</option>
+ <option value=4>All messages</option>
+ </select>
+ </label>

<label> </label>
<input class='btn btn-primary' type='submit' value='Send A Test Email' class='submit' />
diff -bcr ../UserSpice41/users/helpers/helpers.php ./users/helpers/helpers.php
*** ../UserSpice41/users/helpers/helpers.php 2016-08-15 15:51:52.583452900 +0200
--- ./users/helpers/helpers.php 2016-08-23 18:14:53.755615900 +0200
***************
*** 108,116 ****
$smtp_password=$results->email_pass;
$smtp_transport=$results->transport;

! $mail = new PHPMailer;

//$mail->SMTPDebug = 3; // Enable verbose debug output

$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $smtp_server; // Specify main and backup SMTP servers
--- 108,119 ----
$smtp_password=$results->email_pass;
$smtp_transport=$results->transport;

! $exceptions = (isset($_POST['PHPMailerExceptions']) ? $_POST['PHPMailerExceptions'] : false);
! $mail = new PHPMailer($exceptions);

//$mail->SMTPDebug = 3; // Enable verbose debug output
+ if (isset($_POST['SMTPDebug']))
+ $mail->SMTPDebug = $_POST['SMTPDebug'];

$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $smtp_server; // Specify main and backup SMTP servers
  Reply
#2
Thank you for this. I'm probably going to turn this into a documentation/walkthrough if that's ok.

And yeah...I accidentally let a set of email configs go into the wild once. It wasn't a fun time. haha.

Again THANK YOU for contributing this!
  Reply
#3
In email_test.php around line 62 I have adjusted this to make use of the alert classes to make the final result stand out better:

if($mail_result){
echo '<div class="alert alert-success" role="alert">Mail sent successfully</div><br/>';
}else{
echo '<div class="alert alert-danger" role="alert">Mail ERROR</div><br/>';
}

Not sure if the role="alert" is necessary or not, but the class makes things look a lot nicer.
  Reply
#4
Got it! Thank you. I've added that to my documentation notes as well.
  Reply
#5
The more I thought about it the more I realized my previous patch was simply non-helpful. Who wants debug capabilities as part of a form which can potentially be turned on simply by posting a value?!

Here's an alternate patch which helps both with the SMTPDebug (now simply documented to go to helpers.php and set the PHP variable - keeping someone from having to trace the includes to the bitter end) as well as improving the CSS columns/classes in email_test.php:

diff -bcr ../UserSpice41/users/email_test.php ./users/email_test.php
*** ../UserSpice41/users/email_test.php 2016-08-15 15:51:50.062520500 +0200
--- ./users/email_test.php 2016-08-25 14:59:55.767586500 +0200
***************
*** 17,22 ****
--- 17,30 ----
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
+ /* DEVELOPER NOTE:
+ If you are having difficulty with your email configuration, go to
+ users/helpers/helpers.php (around line 114) and set $mail->SMTPDebug
+ to a non-zero value. This is a development-platform-ONLY setting - be
+ sure to set it back to zero (or leave it unset) on any live platform -
+ otherwise you would open significant security holes.
+ */
?>
<?php require_once 'init.php'; ?>
<?php require_once $abs_us_root.$us_url_root.'users/includes/header.php'; ?>
***************
*** 27,46 ****
Redirect::to('account.php');
}
?>
- <?php
- //PHP Goes Here!
-
- $query = $db->query("SELECT * FROM email");
- $results = $query->first();
-
- if(!empty($_POST)){
- $to = $_POST['test_acct'];
- $subject = 'Testing Your Email Settings!';
- $body = 'This is the body of your test email';
- $mail_result=email($to,$subject,$body);
- }
-
- ?>
<div id="page-wrapper">

<div class="container-fluid">
--- 35,40 ----
***************
*** 49,59 ****
<div class="row">
<div class="col-sm-12">

- <!-- Left Column -->
- <div class="class col-sm-4"></div>
-
<!-- Main Center Column -->
! <div class="class col-sm-3">
<!-- Content Goes Here. Class width can be adjusted -->
<h1>
Test your email settings.
--- 43,50 ----
<div class="row">
<div class="col-sm-12">

<!-- Main Center Column -->
! <div class="class col-xs-12 col-sm-offset-1 col-sm-10 col-md-offset-2 col-md-8 col-lg-offset-3 col-lg-6">
<!-- Content Goes Here. Class width can be adjusted -->
<h1>
Test your email settings.
***************
*** 61,89 ****
It's a good idea to test to make sure you can actually receive system emails before forcing your users to verify theirs. <br><br>
<?php
if (!empty($_POST)){
if($mail_result){
! echo 'Mail sent successfully<br/>';
}else{
! echo 'Mail ERROR<br/>';
}
-
}
-
?>

<form class="" name="test_email" action="email_test.php" method="post">
<label>Send test to (Ideally different than your from address):
<input required size='50' class='form-control' type='text' name='test_acct' value='' /></label>

! <label> </label>
<input class='btn btn-primary' type='submit' value='Send A Test Email' class='submit' />
</form>

<!-- End of main content section
</div>

-
- <div class="class col-sm-1"></div>
</div>
</div>

--- 52,86 ----
It's a good idea to test to make sure you can actually receive system emails before forcing your users to verify theirs. <br><br>
<?php
if (!empty($_POST)){
+ /* these appear to be unused
+ $query = $db->query("SELECT * FROM email");
+ $results = $query->first();
+ */
+
+ $to = $_POST['test_acct'];
+ $subject = 'Testing Your Email Settings!';
+ $body = 'This is the body of your test email';
+ $mail_result=email($to,$subject,$body);
+
if($mail_result){
! echo '<div class="alert alert-success" role="alert">Mail sent successfully</div><br/>';
}else{
! echo '<div class="alert alert-danger" role="alert">Mail ERROR</div><br/>';
}
}
?>

<form class="" name="test_email" action="email_test.php" method="post">
<label>Send test to (Ideally different than your from address):
<input required size='50' class='form-control' type='text' name='test_acct' value='' /></label>

! <label> </label><br />
<input class='btn btn-primary' type='submit' value='Send A Test Email' class='submit' />
</form>

<!-- End of main content section
</div>

</div>
</div>

diff -bcr ../UserSpice41/users/helpers/helpers.php ./users/helpers/helpers.php
*** ../UserSpice41/users/helpers/helpers.php 2016-08-15 15:51:52.583452900 +0200
--- ./users/helpers/helpers.php 2016-08-25 14:44:05.035763700 +0200
***************
*** 110,116 ****

$mail = new PHPMailer;

! //$mail->SMTPDebug = 3; // Enable verbose debug output

$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $smtp_server; // Specify main and backup SMTP servers
--- 110,119 ----

$mail = new PHPMailer;

! /*
! $mail->SMTPDebug = 3; // Enable verbose debug output
! $mail->Debugoutput = 'html'; // debug output displays well in html
! */

$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $smtp_server; // Specify main and backup SMTP servers
  Reply
#6
I just noticed (in your other post) that you preferred pastebin patches. Here's the same patch in a pastebin:

http://pastebin.com/aSK9sVYF
  Reply
#7
Thanks! I'll take a look
  Reply
#8
Would you mind pasting your entire email_test.php file so I can look at it as a whole?
  Reply
#9
http://pastebin.com/hCCg0CwA
  Reply
#10
Thanks for that!
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)