Not able to send Email through windows Scheduler

General discussion of Mantis.

Moderators: Developer, Contributor

Post Reply
ghansham_tiwari
Posts: 6
Joined: 09 Jun 2014, 09:22

Not able to send Email through windows Scheduler

Post by ghansham_tiwari »

Hi,

Running mantis on WAMP server.
Email are configured to be sent through Gmail and working fine without cronjob but is causing a lot of performance slowdown.

when try to send Emails through windows scheduler, getting the following error in mantis logs
ERROR: Message could not be sent - SMTP Error: Could not connect to SMTP host.

I have commented the following lines in send_emails.php file and is working fine without scheduler.
if( php_sapi_name() != 'cli' ) {
echo "send_emails.php is not allowed to run through the webserver.\n";
exit( 1 );

Following are the config file options.

$g_enable_email_notification = ON;
$g_phpMailer_method = PHPMAILER_METHOD_SMTP;
$g_from_email = 'XXXXXXXX';
$g_smtp_host = 'smtp.gmail.com';
$g_smtp_port = '465';
$g_smtp_username = 'XXXXXX';
$g_smtp_password = 'XXXXXXX';
$g_smtp_connection_mode = 'ssl';
$g_email_send_using_cronjob = ON;
Please guide me, what am I doing wrong and What could be the possible Solution for this.

Thanks in Adnace
Ghansham
atrol
Site Admin
Posts: 8573
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Not able to send Email through windows Scheduler

Post by atrol »

ghansham_tiwari wrote: when try to send Emails through windows scheduler,
Not sure I can provide help as I don't use Windows/WAMP to run MantisBT.
Maybe WAMP comes with more than one php.exe (one for command line interface and one for web server) and you chooses the wrong one in scheduler.
Please use Search before posting and read the Manual
ghansham_tiwari
Posts: 6
Joined: 09 Jun 2014, 09:22

Re: Not able to send Email through windows Scheduler

Post by ghansham_tiwari »

Hi,

Thanks for your reply, Here are the commands that I have tried using:

C:\wamp\bin\php\php5.4.12\php-cgi.exe C:\wamp\www\defecttracker\scripts\send_emails.php
C:\wamp\bin\php\php5.4.12\php.exe C:\wamp\www\defecttracker\scripts\send_emails.php

Does it make any sense?
atrol
Site Admin
Posts: 8573
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Not able to send Email through windows Scheduler

Post by atrol »

Maybe there is alsp a php-cli.exe ?
Try also
C:\wamp\bin\php\php5.4.12\php.exe -f C:\wamp\www\defecttracker\scripts\send_emails.php
Please use Search before posting and read the Manual
ghansham_tiwari
Posts: 6
Joined: 09 Jun 2014, 09:22

Re: Not able to send Email through windows Scheduler

Post by ghansham_tiwari »

Thanks for reply,
atrol wrote:Maybe there is alsp a php-cli.exe ?
Try also
C:\wamp\bin\php\php5.4.12\php.exe -f C:\wamp\www\defecttracker\scripts\send_emails.php
There is no "php-cli.exe"

tried with "-f " Still getting the same error :
ERROR: Message could not be sent - SMTP Error: Could not connect to SMTP host.

My guess is, the problem should not be the command that is being executed as it is invoking the "send_emails.php" file. But somewhere else, because that function is not able to connect to the Gmail SMTP server. May be the problem is in SMTP settings or if there is any SMTP session being created.
But at the same time the Same settings are working fine if Cronjob is disabled.
ghansham_tiwari
Posts: 6
Joined: 09 Jun 2014, 09:22

Re: Not able to send Email through windows Scheduler

Post by ghansham_tiwari »

Hi

I just figured out the solution to the problem.

Problem was: WAMP server keeps a copy of PHP.ini in apache folder, that is used while running the PHP instance
Folder path: \wamp\bin\apache\Apache2.4.4\bin

While trying to run PHP.exe, windows accesses the PHP.ini file from PHP folder itself, therefore php_openssl setting is disabled due to its default setting in the file.

Solution:
Just copy the PHP.ini file from Apache folder to the PHP folder.

Anyone trying to configure a windows scheduler service to run a PHP program should try this fix.
I spent more than a week to figure out such simple solution. Therefore wanted to share it with others who might be facing the same problem.
atrol
Site Admin
Posts: 8573
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Not able to send Email through windows Scheduler

Post by atrol »

Thanks for coming back and telling the solution.
Please use Search before posting and read the Manual
Post Reply