email configuration

359 views
Skip to first unread message

Nicolas Bruneau

unread,
Jan 19, 2022, 4:09:57 AM1/19/22
to jorani
Hi All,

I'm done with the installation, it went quite well.
My only problem right now is the configuration to send email.

We have office 365 and I know that some time it can be a hassle to configure it. 
So, as we have also ovh I tried it.

Here is my conf file : 
?php defined('BASEPATH') OR exit('No direct script access allowed.');

$config['useragent']        = 'PHPMailer';              // Mail engine switcher: 'CodeIgniter' or 'PHPMailer'
$config['protocol']         = 'smtp';                   // 'mail', 'sendmail', or 'smtp'
$config['mailpath']         = '/usr/sbin/sendmail';
$config['smtp_host']        = 'smtp.****.com';
$config['smtp_auth']        = 'TRUE';                     // Whether to use SMTP authentication, boolean TRUE/FALSE. If this option >
$config['smtp_user']        = '***envoi***@*****.com';
$config['smtp_pass']        = '*******';
$config['smtp_port']        = 587;
$config['smtp_timeout']     = 30;                       // (in seconds)
$config['smtp_crypto']      = 'tls';                       // '' or 'tls' or 'ssl'
$config['smtp_debug']       = 0;                        // PHPMailer's SMTP debug info level: 0 = off, 1 = commands, 2 = commands an>
$config['smtp_auto_tls']    = FALSE;                     // Whether to enable TLS encryption automatically if a server supports it, >
$config['smtp_conn_options'] = array();                 // SMTP connection options, an array passed to the function stream_context_c>
$config['wordwrap']         = TRUE;
$config['wrapchars']        = 76;
$config['mailtype']         = 'html';                   // 'text' or 'html'
$config['charset']          = 'UTF-8';                  // 'UTF-8', 'ISO-8859-15', ...; NULL (preferable) means config_item('charset>
$config['validate']         = TRUE;
$config['priority']         = 3;                        // 1, 2, 3, 4, 5; on PHPMailer useragent NULL is a possible option, it means>
$config['crlf']             = "\n";                     // "\r\n" or "\n" or "\r"
$config['newline']          = "\n";                     // "\r\n" or "\n" or "\r"
$config['bcc_batch_mode']   = FALSE;
$config['bcc_batch_size']   = 200;
$config['encoding']         = '8bit';                   // The body encoding. For CodeIgniter: '8bit' or '7bit'. For PHPMailer: '8bi>
$config['from_mail'] = '****@*****.fr'

Did I miss something ?
When I open the page to check my email configuration, it is just writte : "Test of your e-mail configuration" but I can wait and wait and nothing happen;
 I aslo tried to reset a user password but I don't receive any email.

I don't know where to find the log.
Also, when I modify the email.php, what do I need to restart ? To be sure I'm restarting apache.

Thanks for your help.

Nicolas Bruneau

unread,
Jan 19, 2022, 4:24:24 AM1/19/22
to jorani
  Ok so I found this in the apache logs : 

[Wed Jan 19 10:02:13.205955 2022] [php7:error] [pid 78291] [client 10.0.0.22:56286] PHP Parse error:  syntax error, unexpected '$config' (T_VARIABLE) in /var/w
ww/html/jorani/application/config/email.php on line 33, referer: http://192.168.1.150/jorani/requirements.php
[Wed Jan 19 10:10:54.122672 2022] [php7:warn] [pid 78291] [client 10.0.0.22:58900] PHP Warning:  define() expects at least 2 parameters, 1 given in /var/www/ht
ml/jorani/testmail.php on line 21, referer: http://192.168.1.150/jorani/requirements.php
[Wed Jan 19 10:10:54.123491 2022] [php7:warn] [pid 78291] [client 10.0.0.22:58900] PHP Warning:  Use of undefined constant EMAIL_ADDRESS - assumed 'EMAIL_ADDRE
SS' (this will throw an Error in a future version of PHP) in /var/www/html/jorani/testmail.php on line 55, referer: http://192.168.1.150/jorani/requirements.ph
p

Here is my testemail.php
<?php
/**
 * This diagnostic page helps you to check email settings.
 * You can use this script in order to try to send an email with a debug trace.
 * @copyright  Copyright (c) 2014-2019 Benjamin BALET
 * @license      http://opensource.org/licenses/AGPL-3.0 AGPL-3.0
 * @link            https://github.com/bbalet/jorani
 * @since         0.4.0
 */

require_once 'vendor/autoload.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

define('BASEPATH', '.'); //Make this script works with nginx
$env = is_null(getenv('CI_ENV'))?'':getenv('CI_ENV');
//Configuration values are taken from application/config/(env)/email.php
//-----------------------------------------------------------------
//Please enter a valid target email address. A test email will be sent here
define('nicolas...@encluisois.fr');

//-----------------------------------------------------------------
?>
<html>
    <head>
        <title>Jorani Email Configuration</title>
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <link rel="icon" type="image/x-icon" href="favicon.ico" sizes="32x32">
        <link rel="stylesheet" href="assets/dist/requirements.css">
        <script type="text/javascript" src="assets/dist/requirements.js"></script>
    </head>
    <body>
        <div class="container">

            <ul class="nav nav-pills">
                <li class="nav-item"><a class="nav-link" href="home" title="login to Jorani"><i class="mdi mdi-home nolink"></i></a></li>
                <li class="nav-item"><a class="nav-link" href="requirements.php">Requirements</a></li>
                <li class="nav-item"><a class="nav-link active" href="#">Email</a></li>
                <li class="nav-item"><a class="nav-link" href="testldap.php">LDAP</a></li>
                <li class="nav-item"><a class="nav-link" href="testssl.php">SSL</a></li>
                <li class="nav-item"><a class="nav-link" href="testoauth2.php">OAuth2</a></li>
                <li class="nav-item"><a class="nav-link" href="testapi.php">API HTTP</a></li>
            </ul>

            <h1>Test of your e-mail configuration</h1>

<?php
//Check if we can access to the configuration file
$pathCIConfigFile = realpath(join(DIRECTORY_SEPARATOR, array('application', 'config', $env, 'config.php')));
$pathConfigFile = realpath(join(DIRECTORY_SEPARATOR, array('application', 'config', $env, 'email.php')));
$configCIFileExists = file_exists($pathCIConfigFile);
$configFileExists = file_exists($pathConfigFile);

if (EMAIL_ADDRESS == '') {
    echo '<div class="alert alert-danger" role="alert"><b>ERROR:</b> Please provide a valid e-mail address in testmail.php.</div>' . PHP_EOL;
} else {
    if ($configFileExists && $configCIFileExists) {
        include $pathCIConfigFile;
        include $pathConfigFile;
        try {
            //Include shipped PHPMailer library
            $mail = new PHPMailer(true); //true => throw exceptions on error
            $mail->SMTPDebug = 1;     //Errors and messages
            $mail->Debugoutput = function($str, $level) {
                echo nl2br($str);
            };

            //Test if we use SMTP protocol
            if (strcasecmp($config['protocol'], 'smtp') == 0) {
                echo '<b>INFO:</b> Selecting SMTP Protocol.<br />' . PHP_EOL;
                $mail->IsSMTP();
                $mail->Host = $config['smtp_host'];
                $mail->Port = $config['smtp_port'];
                $mail->SMTPAutoTLS = $config['smtp_auto_tls'];
                if (strpos($config['smtp_port'], 'gmail') !== false) {
                    echo '<b>INFO:</b> Using GMAIL.<br />' . PHP_EOL;
                }
            }

            //Test if we use sendmail
            if (strcasecmp($config['protocol'], 'sendmail') == 0) {
                echo '<b>INFO:</b> Selecting sendmail.<br />' . PHP_EOL;
                $mail->IsSendmail();
                if (array_key_exists('mailpath', $config)) {
                    if ($config['mailpath'] != '') {
                        echo '<b>INFO:</b> Changing sendmail path.<br />' . PHP_EOL;
                        ini_set('sendmail_path', $config['mailpath']);
                    }
                }
            }

            //GMAIL requires _smtp_auth set to TRUE
            if ($config['smtp_auth'] === TRUE) {
                echo '<b>INFO:</b> SMTP with authentication.<br />' . PHP_EOL;
                $mail->SMTPAuth = true;
                $mail->Username = $config['smtp_user'];
                $mail->Password = $config['smtp_pass'];
            }

            //GMAIL requires smtp_crypto set to tls
            if ($config['smtp_crypto'] != '') {
                echo '<b>INFO:</b> SMTP with crypto.<br />' . PHP_EOL;
                $mail->SMTPSecure = $config['smtp_crypto'];
            }

            $mail->CharSet = $config['charset'];
            $mail->AddAddress(EMAIL_ADDRESS, "Test e-mail");
            $mail->SetFrom($config['from_mail'], "Jorani application");
            $mail->Subject = "Test Message";
            $mail->Body = 'This is a test.';
            $mail->Send();

            echo '<b>INFO:</b> Message sent.<br />' . PHP_EOL;
        } catch (phpmailerException $e) {
            echo '<b>ERROR:</b> PHPMailer has encountered an error.<br />' . PHP_EOL;
            $text = $e->errorMessage();
            $text = iconv(mb_detect_encoding($text, mb_detect_order(), true), "UTF-8", $text);
            echo $text . PHP_EOL;
        } catch (Exception $e) {
            echo '<b>ERROR:</b> Unexpected error.<br />' . PHP_EOL;
            $text = $e->getMessage();
            $text = iconv(mb_detect_encoding($text, mb_detect_order(), true), "UTF-8", $text);
            echo $text . PHP_EOL;
        }
    } else {
        echo '<div class="alert alert-danger" role="alert"><b>ERROR:</b> The configuration doesn\'t exist.</div>' . PHP_EOL;
    }
}
?>
            <h3>Troubleshooting</h2>
                <p>In case of error, here are some additional steps:</p>
                <ul>
                    <li>Check the configuration with your IT Admin team.</li>
                    <li>If you are using GMAIL, please read <a target="_blank" href="https://support.google.com/mail/answer/78775?hl=en">this article</a>.</li>
                    <li>The STMP port may be blocked by your organization/server's security policy (firewall, etc.).</li>
                    <li>When running SELinux, the webserver is blocked by default (it cannot send e-mails or open a network connection). Please consider unblocking it:
                        <p>
<pre>
$ setsebool -P httpd_can_sendmail 1
$ setsebool -P httpd_can_network_connect 1
</pre>
                        </p>
                    </li>
                    <li>Some e-mail servers (eg Office 360) require to set a valid sender e-mail. Update <tt>config/config.php</tt>
                        <p>
                            <code>$config['from_mail'] = 'do....@reply.me';</code>
                        </p>
                    </li>
                    <li>Some antivirus block STMP port by default.</li>
                    <li>Some SMTP server require the application server sending emails (i.e. Jorani) to be whitelisted (on the SMTP server).</li>
                    <li>Your webhosting company may forbid email functions.</li>
                    <li>Maybe that the emails are sent but put into SPAM folder.</li>
                </ul>
        </div>
    </body>
</html>

Nicolas Bruneau

unread,
Jan 19, 2022, 4:35:15 AM1/19/22
to jorani
Ok I assume that I had an error in testmail.php

So I corrected it like that :  (line in bold)

/**
 * This diagnostic page helps you to check email settings.
 * You can use this script in order to try to send an email with a debug trace.
 * @copyright  Copyright (c) 2014-2018 Benjamin BALET

 * @license      http://opensource.org/licenses/AGPL-3.0 AGPL-3.0
 * @link            https://github.com/bbalet/jorani
 * @since         0.4.0
 */

define('BASEPATH', '.'); //Make this script works with nginx
$env = is_null(getenv('CI_ENV'))?'':getenv('CI_ENV');
//Configuration values are taken from application/config/(env)/email.php
//-----------------------------------------------------------------
//Please enter a valid target email address. A test email will be sent here
define('EMAIL_ADDRESS', 'nicolas...@enclunisois.fr');

It seems that I do not have this error anymore in the apache log. but still does not work.

Nicolas Bruneau

unread,
Jan 20, 2022, 2:37:16 AM1/20/22
to jorani
Nobody to help ? :-/

Benjamin BALET

unread,
Jan 20, 2022, 3:18:51 AM1/20/22
to jorani
PHP Parse error: syntax error, unexpected (T_VARIABLE)
means that PHP encountered an unknown variable while reading config/email.php
While attempting to make it work, you might have deleted something important without noticing it.
My advice is to try to rebuild config/email.php from scratch (an original version of this file).

--
You received this message because you are subscribed to the Google Groups "jorani" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jorani+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jorani/66305e31-4e7f-4a0e-a5da-e8a7d3e7f562n%40googlegroups.com.

Nicolas Bruneau

unread,
Jan 20, 2022, 4:38:33 AM1/20/22
to jorani
Thanks for your help Benjamin.
So I rebuilt my email.php from scratch.

the email still does not work. So far in the apache log I have this : 

[Thu Jan 20 10:28:37.134140 2022] [php7:error] [pid 28024] [client 10.0.0.18:52935] script '/var/www/html/requirements.php' not found or unable to stat
[Thu Jan 20 10:28:54.053319 2022] [php7:warn] [pid 28022] [client 10.0.0.18:52958] PHP Warning:  require_once(/var/www/html/jorani): failed to open stream: No
 such file or directory in /var/www/html/jorani/testmail.php on line 58, referer: https://192.168.1.150/jorani/requirements.php
[Thu Jan 20 10:28:54.053402 2022] [php7:error] [pid 28022] [client 10.0.0.18:52958] PHP Fatal error:  require_once(): Failed opening required '' (include_path
='.:/usr/share/php') in /var/www/html/jorani/testmail.php on line 58, referer: https://192.168.1.150/jorani/requirements.php
[Thu Jan 20 10:29:00.675565 2022] [php7:warn] [pid 41963] [client 10.0.0.18:52973] PHP Warning:  require_once(/var/www/html/jorani): failed to open stream: No
 such file or directory in /var/www/html/jorani/testmail.php on line 58, referer: https://192.168.1.150/jorani/testoauth2.php
[Thu Jan 20 10:29:00.675647 2022] [php7:error] [pid 41963] [client 10.0.0.18:52973] PHP Fatal error:  require_once(): Failed opening required '' (include_path
='.:/usr/share/php') in /var/www/html/jorani/testmail.php on line 58, referer: https://192.168.1.150/jorani/testoauth2.php

When I look at my requirement I'm missing few things but I don't think they are related to email.

jorani.png

kenzo

unread,
Jan 20, 2022, 8:31:50 AM1/20/22
to jor...@googlegroups.com
Bonjour

Depuis deux jours j'ai un utilisateur qui n'arrive plus à se connecter avec ses identifiants.
Je précise que chez moi Jorani est installé avec une authentification CAS, et pour cet utilisateur ni son mot de passe inscrit en dur dans Jorani, ni son mot de passe du CAS ne fonctionnent .

Quel est le soucis  ?
Merci
---------------------------------------------------------------------------
Kim  Danière
22 rue Pierre Fourel
69230 Saint Genis Laval

tel : 06 77 46 78 74
Mèl : kim.daniere@gmail.com
skype : kenzotao

---------------------------------------------------------------------------
Progressons vers l'éco-citoyenneté en économisant le papier.
N'imprimez ce message que si nécessaire.
---------------------------------------------------------------------------

Garanti sans virus. www.avast.com

Benjamin BALET

unread,
Jan 20, 2022, 8:34:08 AM1/20/22
to jorani
Il est peut être désactivé (à vérifier via admin/utilisateurs)

--
You received this message because you are subscribed to the Google Groups "jorani" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jorani+un...@googlegroups.com.

kenzo

unread,
Jan 20, 2022, 8:40:39 AM1/20/22
to jor...@googlegroups.com
Benjamin,

oui c'était cela mais je m'explique pas pourquoi cet utilisateur à été désactivé ...?

Merci
---------------------------------------------------------------------------
Kim  Danière
22 rue Pierre Fourel
69230 Saint Genis Laval

tel : 06 77 46 78 74
Mèl : kim.daniere@gmail.com
skype : kenzotao

---------------------------------------------------------------------------
Progressons vers l'éco-citoyenneté en économisant le papier.
N'imprimez ce message que si nécessaire.
---------------------------------------------------------------------------


Garanti sans virus. www.avast.com

Benjamin BALET

unread,
Jan 20, 2022, 8:45:17 AM1/20/22
to jorani
Fausse manipulation d'un utilisateur peut être.
Il n'y pas de code gérant CAS dans jorani (à part si vous passez par saml). Je ne sais pas ce qui a été codé dans ce que vous avez ajouté. Peut être une désactivation du compte en cas d'échec de l'authentification.

kenzo

unread,
Jan 20, 2022, 9:10:15 AM1/20/22
to jor...@googlegroups.com
D'accord je vais aller regarder ma conf de cas ..
Merci
---------------------------------------------------------------------------
Kim  Danière
22 rue Pierre Fourel
69230 Saint Genis Laval

tel : 06 77 46 78 74
Mèl : kim.daniere@gmail.com
skype : kenzotao

---------------------------------------------------------------------------
Progressons vers l'éco-citoyenneté en économisant le papier.
N'imprimez ce message que si nécessaire.
---------------------------------------------------------------------------


Garanti sans virus. www.avast.com

Reply all
Reply to author
Forward
0 new messages