08-23-2016, 02:52 PM
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
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