SMTP email with Mantis 1.2.11

Get help from other users here.

Moderators: Developer, Contributor

brillox
Posts: 14
Joined: 09 Nov 2012, 17:12

SMTP email with Mantis 1.2.11

Post by brillox »

I am unable to send email from Mantis on a windows server 2008 R2 with firewall turned off.

Below my config_inc.php values. If I telnet the SMTP server I use I get a response and Mantis does not has any error ; i ahev also enabled logs.

$g_phpMailer_method = 'PHPMAILER_METHOD_SMTP'; # or PHPMAILER_METHOD_SMTP, PHPMAILER_METHOD_SENDMAIL, PHPMAILER_METHOD_MAIL
$g_smtp_host = 'mail.authsmtp.com';# used with PHPMAILER_METHOD_SMTP
$g_smtp_username = 'xxxxxxxx';# used with PHPMAILER_METHOD_SMTP
$g_smtp_password = xxxxxxx';# used with PHPMAILER_METHOD_SMTP
$g_smtp_port = 2525;


$g_log_level = LOG_EMAIL | LOG_EMAIL_RECIPIENT | LOG_FILTERING | LOG_AJAX;

can anyone help me; I tried to search the forum and I can see that others had issues in previous versions, but I am unable to get a solution

Thanks
atrol
Site Admin
Posts: 8575
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: SMTP email with Mantis 1.2.11

Post by atrol »

Please use Search before posting and read the Manual
brillox
Posts: 14
Joined: 09 Nov 2012, 17:12

Re: SMTP email with Mantis 1.2.11

Post by brillox »

I am afraid all the solutions posted there did not work for me.

I can telnet from the server the SMTP service so I know I can talk to it. If I try the test_email.php I get a generic error message that does not point me to the problem.

I really need help please
brillox
Posts: 14
Joined: 09 Nov 2012, 17:12

Re: SMTP email with Mantis 1.2.11

Post by brillox »

I have actually debugged mantis in netbeans PHP IDE and after trying the test_email.php with my config info, this is the error I get

Code: Select all

phpmailerException object {
  message => (string) Could not instantiate mail function.
  *Exception*string => (string)
  code => (int) 2
  file => (string) C:\inetpub\wwwroot\mantisbt\library\phpmailer\class.phpmailer.php
  line => (int) 687
  *Exception*trace => array(3) (
    [0] => array(6) (
      [file] => (string) C:\inetpub\wwwroot\mantisbt\library\phpmailer\class.phpmailer.php
      [line] => (int) 578
      [function] => (string) MailSend
      [class] => (string) PHPMailer
      [type] => (string) ->
      [args] => array(2) (
      )
    )
    [1] => array(6) (
      [file] => (string) C:\inetpub\wwwroot\mantisbt\core\email_api.p...
seems like we have a bug guys !!
brillox
Posts: 14
Joined: 09 Nov 2012, 17:12

Re: SMTP email with Mantis 1.2.11

Post by brillox »

another bit of info...

on phpmailer.php, at the code from line 572

Code: Select all

 switch($this->Mailer) {
        case 'sendmail':
          return $this->SendmailSend($header, $body);
        case 'smtp':
          return $this->SmtpSend($header, $body);
        default:
          return $this->MailSend($header, $body);
      }
although on my config_inc I do have PHPMAILER_METHOD_SMTP for $g_phpMailer_method

the code does not stop at the case SmtpSend but goes to the default and choose MailSend

anybody can figure out why ??
brillox
Posts: 14
Joined: 09 Nov 2012, 17:12

Re: SMTP email with Mantis 1.2.11

Post by brillox »

and further on...

on the standard.php file the function

Code: Select all

function mail ($to, $subject, $message, $additional_headers = null, $additional_parameters = null) {}
is returning false to

Code: Select all

private function mail_passthru($to, $subject, $body, $header, $params) in phpmailer.php
and this is causing

Code: Select all

protected function MailSend($header, $body)
to trow the error

hope all this can help someone to help me with this
brillox
Posts: 14
Joined: 09 Nov 2012, 17:12

Re: SMTP email with Mantis 1.2.11

Post by brillox »

if I modify the code of the phpmailer.php to send with SMTP by default, I now get

Code: Select all

phpmailerException object {
  message => (string) The following From address failed: noreply@bluehorseassociates.com
  *Exception*string => (string)
  code => (int) 2
  file => (string) C:\inetpub\wwwroot\mantisbt\library\phpmailer\class.phpmailer.php
  line => (int) 903
  *Exception*trace => array(7) (
    [0] => array(6) (
      [file] => (string) C:\inetpub\wwwroot\mantisbt\library\phpmailer\class.phpmailer.php
      [line] => (int) 771
      [function] => (string) SmtpSend
      [class] => (string) PHPMailer
      [type] => (string) ->
      [args] => array(2) (
      )
    )
I am going to change the from to a gmail adrress ??? going crazy here !!
brillox
Posts: 14
Joined: 09 Nov 2012, 17:12

Re: SMTP email with Mantis 1.2.11

Post by brillox »

finally I have got the solution !!!

guys you are bad.. really bad... :D

how can you have a switch statement that is comparing a string to a non string value ???

by simply changing the email_api.php snipped of code from line 904 in the function email_send( $p_email_data ) method

from

Code: Select all

# Select the method to send mail  
 	switch($config_get('phpMailer_method')) {
		case PHPMAILER_METHOD_MAIL:
			$mail->IsMail();
			break;

		case PHPMAILER_METHOD_SENDMAIL:
			$mail->IsSendmail();
			break;

		case PHPMAILER_METHOD_SMTP:
			$mail->IsSMTP();
......
to

Code: Select all

# Select the method to send mail
    $MailMethod = config_get('phpMailer_method');
    
	switch($MailMethod) {
		case 'PHPMAILER_METHOD_MAIL':
			$mail->IsMail();
			break;

		case 'PHPMAILER_METHOD_SENDMAIL':
			$mail->IsSendmail();
			break;

		case 'PHPMAILER_METHOD_SMTP':
			$mail->IsSMTP();
I finally managed to get emails working fine.

you should add this bit of my post to the http://www.mantisbt.org/forums/viewtopi ... =3&t=15398 post you suggested me to follow.

please reply with your comments on this

Thanks
atrol
Site Admin
Posts: 8575
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: SMTP email with Mantis 1.2.11

Post by atrol »

There is no bug in MantisBT.
Your configuration is wrong.
You have to set $g_phpMailer_method the way it's documented
$g_phpMailer_method

Select the method to mail by: PHPMAILER_METHOD_MAIL for use of mail() function, PHPMAILER_METHOD_SENDMAIL for sendmail (or postfix), PHPMAILER_METHOD_SMTP for SMTP. Default is PHPMAILER_METHOD_MAIL.

Code: Select all

$g_phpMailer_method = PHPMAILER_METHOD_SMTP;
PHPMAILER_METHOD_SMTP is a defined constant, not a string, so you should not use quotes.
Unfortunately I didn't notice the quotes when having a look at your configuration.

Do you agree that you are the bad guy?
Please use Search before posting and read the Manual
brillox
Posts: 14
Joined: 09 Nov 2012, 17:12

Re: SMTP email with Mantis 1.2.11

Post by brillox »

there is a bug in mantis; I tried every single method and it was not working until I made the changes on the code I posted below; I am afraid but is a bug; maybe not on Linux, but definitely in Windows. And then,. why I should use MAILl if I use SMTP ??? in the doc SMTP is supported.. so I think you are a bit wrong
atrol
Site Admin
Posts: 8575
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: SMTP email with Mantis 1.2.11

Post by atrol »

Please read exactly what I wrote before:
PHPMAILER_METHOD_SMTP is a defined constant, not a string, so you should not use quotes.
The bug is in your configuration, you have to set

Code: Select all

$g_phpMailer_method = PHPMAILER_METHOD_SMTP;
and not

Code: Select all

$g_phpMailer_method = 'PHPMAILER_METHOD_SMTP';
This is no MantisBT bug.
Please use Search before posting and read the Manual
brillox
Posts: 14
Joined: 09 Nov 2012, 17:12

Re: SMTP email with Mantis 1.2.11

Post by brillox »

please read exactly what I posted before ; the defined constant does not work ! the string it does; explain to me why
brillox
Posts: 14
Joined: 09 Nov 2012, 17:12

Re: SMTP email with Mantis 1.2.11

Post by brillox »

my apologies to all of you guys.

I can see it now.. my wrong, totally

atrol is right.
brillox
Posts: 14
Joined: 09 Nov 2012, 17:12

Re: SMTP email with Mantis 1.2.11

Post by brillox »

however it does not work :-)
brillox
Posts: 14
Joined: 09 Nov 2012, 17:12

Re: SMTP email with Mantis 1.2.11

Post by brillox »

my config now

Code: Select all

$g_phpMailer_method	= PHPMAILER_METHOD_SMTP; # or PHPMAILER_METHOD_SMTP, PHPMAILER_METHOD_SENDMAIL, PHPMAILER_METHOD_MAIL
$g_smtp_host			= 'mail.authsmtp.com';# used with PHPMAILER_METHOD_SMTP
$g_smtp_port = 2525;
$g_smtp_username		= 'xxxxxxx';# used with PHPMAILER_METHOD_SMTP
$g_smtp_password		= 'xxxxxxx';# used with PHPMAILER_METHOD_SMTP

and the method that I modified before and now reverted

Code: Select all

# Select the method to send mail
   # $MailMethod = config_get('phpMailer_method');
    
	switch(config_get('phpMailer_method')) {
		case PHPMAILER_METHOD_MAIL:
			$mail->IsMail();
			break;

		case PHPMAILER_METHOD_SENDMAIL:
			$mail->IsSendmail();
			break;

		case PHPMAILER_METHOD_SMTP:
			$mail->IsSMTP();

			// SMTP collection is always kept alive
			$mail->SMTPKeepAlive = true;

			if ( !is_blank( config_get( 'smtp_username' ) ) ) {
				# Use SMTP Authentication
				$mail->SMTPAuth = true;
				$mail->Username = config_get( 'smtp_username' );
				$mail->Password = config_get( 'smtp_password' );
			}

			if ( !is_blank( config_get( 'smtp_connection_mode' ) ) ) {
				$mail->SMTPSecure = config_get( 'smtp_connection_mode' );
			}

			$mail->Port = config_get( 'smtp_port' );

			break;
	}

Post Reply