[RC1] BetterSMTP

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
Norm99
Registered User
Posts: 1
Joined: Fri May 25, 2007 10:16 pm

Re: [RC1] BetterSMTP

Post by Norm99 » Fri May 25, 2007 10:19 pm

I think someone mentioned this earlier but never got an answer. I'm still struggling with getting open ssl running, but the new problem i have is the error page i normally get after sending a mass email is now blank. Is this a common problem or did i mess something up on the install?

bartezas16
Registered User
Posts: 59
Joined: Tue Mar 28, 2006 4:06 pm

Re: [RC1] BetterSMTP

Post by bartezas16 » Sat Jun 16, 2007 9:36 am

after i installed this mod and trying send mass mail i getting this (see picture) :

http://img157.imageshack.us/img157/2733/asdfkr0.png

Void Main
Registered User
Posts: 6
Joined: Sun Jun 17, 2007 6:22 am

Re: [RC1] BetterSMTP

Post by Void Main » Sun Jun 17, 2007 6:33 am

I have found this BetterSMTP is not needed to send mail through smtp.gmail.com. If you are running phpBB on PHP 5 you only have to make a slight addition to includes/smtp.php. I am running 2.0.20 but it will probably work on later versions too. Just find this section:

Code: Select all

        if( !empty($board_config['smtp_username']) && !empty($board_config['smtp_password']) )
        {
                fputs($socket, "EHLO " . $board_config['smtp_host'] . "\r\n");
                server_parse($socket, "250", __LINE__);
and right after it add this:

Code: Select all

fputs($socket, "STARTTLS\r\n");
server_parse($socket, "220", __LINE__);
stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
That would be right before the "AUTH LOGIN" section. Then in your board configuration settings use "smtp.gmail.com", port 25 (or 587 I presume) and your gmail address and password for the username and password. Basically this starts TLS right before the auth.

dronchi
Registered User
Posts: 1
Joined: Tue Jun 19, 2007 1:59 am

Re: [RC1] BetterSMTP

Post by dronchi » Tue Jun 19, 2007 2:19 am

Thanks for this post "Void Main". I spent several hours today trying to get my PHPBB to talk to gmail and it now works great. I would add two things however. If this has already been mentioned I apologize for the repeat.

I'm running PHPBB at home on a small Windows server. Making the changes to the smtp.php file alone gave me errors about the stream not allowing Encryption or something to that effect. To get rid of this new error I also uncommented the following DLLs from the php.ini file.

- extension=php_mcrypt.dll
- extension=php_openssl.dll
- extension=php_sockets.dll

I kinda just guessed I needed these dlls, but I'm not really sure if all three are needed.

Also, I changed the port in the smtp.php file from 25 to 587. There's probably a better way to do this.

Code: Select all

	if( !$socket = @fsockopen($board_config['smtp_host'], 587, $errno, $errstr, 20) )
	{
		message_die(GENERAL_ERROR, "Could not connect to smtp host : $errno : $errstr", "", __LINE__, __FILE__);
	}
I'm amazed at how long it took me to find this information and how easy it was to fix once I found it. Are there so few people that are using gmail and other SMTP servers that require TLS? I'm very surprised.

Void Main
Registered User
Posts: 6
Joined: Sun Jun 17, 2007 6:22 am

Re: [RC1] BetterSMTP

Post by Void Main » Tue Jun 19, 2007 4:48 am

Ahh, I don't use Windows so I didn't have to mess with the dll thingies. I can also verify that this works on 2.0.22 since I patched mine up to that level today (there actually aren't any changes in smtp.php between the two versions).

kissitpc
Registered User
Posts: 5
Joined: Tue Jul 17, 2007 1:43 pm

Re: [RC1] BetterSMTP

Post by kissitpc » Tue Jul 17, 2007 2:03 pm

I have done everything that Void Main suggested and dronchi aswell and I get the following error:


Ran into problems sending Mail. Response: 503 5.5.1 RCPT first h1sm12539821nfh

DEBUG MODE

Line : 189
File : smtp.php


any suggestions?

I am using phpBB 2.0.22
With PHP 5.2.1
and MySQL 5.0.37
Running using a IIS webserver on windows

the registration process generates the registration email as I have it set to admin activation and sending mass emails works as does posting etc but I get the above message every time a new user registers.

my smtp.php file is

Code: Select all


<?php
/***************************************************************************
 *                              smtp.php
 *                       -------------------
 *   begin                : Wed May 09 2001
 *   copyright            : (C) 2001 The phpBB Group
 *   email                : support@phpbb.com
 *
 *   $Id: smtp.php,v 1.16.2.11 2005/09/27 20:24:35 grahamje Exp $
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

define('SMTP_INCLUDED', 1);

//
// This function has been modified as provided
// by SirSir to allow multiline responses when 
// using SMTP Extensions
//
function server_parse($socket, $response, $line = __LINE__) 
{
	$server_response = '';
	while (substr($server_response, 3, 1) != ' ') 
	{
		if (!($server_response = fgets($socket, 256))) 
		{ 
			message_die(GENERAL_ERROR, "Couldn't get mail server response codes", "", $line, __FILE__); 
		} 
	} 

	if (!(substr($server_response, 0, 3) == $response)) 
	{ 
		message_die(GENERAL_ERROR, "Ran into problems sending Mail. Response: $server_response", "", $line, __FILE__); 
	} 
}

// Replacement or substitute for PHP's mail command
function smtpmail($mail_to, $subject, $message, $headers = '')
{
	global $board_config;

	// Fix any bare linefeeds in the message to make it RFC821 Compliant.
	$message = preg_replace("#(?<!\r)\n#si", "\r\n", $message);

	if ($headers != '')
	{
		if (is_array($headers))
		{
			if (sizeof($headers) > 1)
			{
				$headers = join("\n", $headers);
			}
			else
			{
				$headers = $headers[0];
			}
		}
		$headers = chop($headers);

		// Make sure there are no bare linefeeds in the headers
		$headers = preg_replace('#(?<!\r)\n#si', "\r\n", $headers);

		// Ok this is rather confusing all things considered,
		// but we have to grab bcc and cc headers and treat them differently
		// Something we really didn't take into consideration originally
		$header_array = explode("\r\n", $headers);
		@reset($header_array);

		$headers = '';
		while(list(, $header) = each($header_array))
		{
			if (preg_match('#^cc:#si', $header))
			{
				$cc = preg_replace('#^cc:(.*)#si', '\1', $header);
			}
			else if (preg_match('#^bcc:#si', $header))
			{
				$bcc = preg_replace('#^bcc:(.*)#si', '\1', $header);
				$header = '';
			}
			$headers .= ($header != '') ? $header . "\r\n" : '';
		}

		$headers = chop($headers);
		$cc = explode(', ', $cc);
		$bcc = explode(', ', $bcc);
	}

	if (trim($subject) == '')
	{
		message_die(GENERAL_ERROR, "No email Subject specified", "", __LINE__, __FILE__);
	}

	if (trim($message) == '')
	{
		message_die(GENERAL_ERROR, "Email message was blank", "", __LINE__, __FILE__);
	}

	// Ok we have error checked as much as we can to this point let's get on
	// it already.
	if( !$socket = @fsockopen($board_config['smtp_host'], 587, $errno, $errstr, 20) )
	{
		message_die(GENERAL_ERROR, "Could not connect to smtp host : $errno : $errstr", "", __LINE__, __FILE__);
	}

	// Wait for reply
	server_parse($socket, "220", __LINE__);

	// Do we want to use AUTH?, send RFC2554 EHLO, else send RFC821 HELO
	// This improved as provided by SirSir to accomodate
	if( !empty($board_config['smtp_username']) && !empty($board_config['smtp_password']) )
	{ 
		fputs($socket, "EHLO " . $board_config['smtp_host'] . "\r\n");
		server_parse($socket, "250", __LINE__);
		
		fputs($socket, "STARTTLS\r\n");
		server_parse($socket, "220", __LINE__);
		stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);

		fputs($socket, "AUTH LOGIN\r\n");
		server_parse($socket, "334", __LINE__);

		fputs($socket, base64_encode($board_config['smtp_username']) . "\r\n");
		server_parse($socket, "334", __LINE__);

		fputs($socket, base64_encode($board_config['smtp_password']) . "\r\n");
		server_parse($socket, "235", __LINE__);
	}
	else
	{
		fputs($socket, "HELO " . $board_config['smtp_host'] . "\r\n");
		server_parse($socket, "250", __LINE__);
	}

	// From this point onward most server response codes should be 250
	// Specify who the mail is from....
	fputs($socket, "MAIL FROM: <" . $board_config['board_email'] . ">\r\n");
	server_parse($socket, "250", __LINE__);

	// Specify each user to send to and build to header.
	$to_header = '';

	// Add an additional bit of error checking to the To field.
	$mail_to = (trim($mail_to) == '') ? 'Undisclosed-recipients:;' : trim($mail_to);
	if (preg_match('#[^ ]+\@[^ ]+#', $mail_to))
	{
		fputs($socket, "RCPT TO: <$mail_to>\r\n");
		server_parse($socket, "250", __LINE__);
	}

	// Ok now do the CC and BCC fields...
	@reset($bcc);
	while(list(, $bcc_address) = each($bcc))
	{
		// Add an additional bit of error checking to bcc header...
		$bcc_address = trim($bcc_address);
		if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address))
		{
			fputs($socket, "RCPT TO: <$bcc_address>\r\n");
			server_parse($socket, "250", __LINE__);
		}
	}

	@reset($cc);
	while(list(, $cc_address) = each($cc))
	{
		// Add an additional bit of error checking to cc header
		$cc_address = trim($cc_address);
		if (preg_match('#[^ ]+\@[^ ]+#', $cc_address))
		{
			fputs($socket, "RCPT TO: <$cc_address>\r\n");
			server_parse($socket, "250", __LINE__);
		}
	}

	// Ok now we tell the server we are ready to start sending data
	fputs($socket, "DATA\r\n");

	// This is the last response code we look for until the end of the message.
	server_parse($socket, "354", __LINE__);

	// Send the Subject Line...
	fputs($socket, "Subject: $subject\r\n");

	// Now the To Header.
	fputs($socket, "To: $mail_to\r\n");

	// Now any custom headers....
	fputs($socket, "$headers\r\n\r\n");

	// Ok now we are ready for the message...
	fputs($socket, "$message\r\n");

	// Ok the all the ingredients are mixed in let's cook this puppy...
	fputs($socket, ".\r\n");
	server_parse($socket, "250", __LINE__);

	// Now tell the server we are done and close the socket...
	fputs($socket, "QUIT\r\n");
	fclose($socket);

	return TRUE;
}

?>


Void Main
Registered User
Posts: 6
Joined: Sun Jun 17, 2007 6:22 am

Re: [RC1] BetterSMTP

Post by Void Main » Tue Jul 17, 2007 4:43 pm

The only difference I see between your file and mine is I am using port 25. I don't think that should matter. From the SMTP response I tend to think you have something wrong with your configuration (on the Admin page). The message would indicate you are trying to send a message but have no recipients (i.e. nobody in the "To:" section). Just a guess. Mine still works just fine....

asifperfect
Registered User
Posts: 2
Joined: Tue Aug 28, 2007 9:30 pm

Re: [RC1] BetterSMTP

Post by asifperfect » Tue Aug 28, 2007 10:05 pm

Void Main wrote:I have found this BetterSMTP is not needed to send mail through smtp.gmail.com. If you are running phpBB on PHP 5 you only have to make a slight addition to includes/smtp.php. I am running 2.0.20 but it will probably work on later versions too. Just find this section:

Code: Select all

        if( !empty($board_config['smtp_username']) && !empty($board_config['smtp_password']) )
        {
                fputs($socket, "EHLO " . $board_config['smtp_host'] . "\r\n");
                server_parse($socket, "250", __LINE__);
and right after it add this:

Code: Select all

fputs($socket, "STARTTLS\r\n");
server_parse($socket, "220", __LINE__);
stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
That would be right before the "AUTH LOGIN" section. Then in your board configuration settings use "smtp.gmail.com", port 25 (or 587 I presume) and your gmail address and password for the username and password. Basically this starts TLS right before the auth.

Thanks, after pasting your code in smtp.php file, and enabling extension=php_openssl.dll in php.ini file my gmail id is working successfuly as my SMTP email address.

Thanks a lot.

Im using phpbb 2.0.22 + Apache/2.2.4 (Win32) + PHP 5.2.1

cabba
Registered User
Posts: 1
Joined: Sun Sep 02, 2007 7:09 pm

Re: [RC1] BetterSMTP

Post by cabba » Sun Sep 02, 2007 7:40 pm

asifperfect wrote:
Thanks, after pasting your code in smtp.php file, and enabling extension=php_openssl.dll in php.ini file my gmail id is working successfuly as my SMTP email address.
Hi, any hint for a newbie on how to do this on a linux box? I'm getting the same reply you were getting,

Code: Select all

Ran into problems sending Mail. Response: 503 5.5.1 RCPT first 19sm4142319ugl

DEBUG MODE

Line : 189
File : smtp.php

radiopatrol
Registered User
Posts: 2
Joined: Sun Sep 09, 2007 7:03 pm

Re: [RC1] BetterSMTP

Post by radiopatrol » Sun Sep 09, 2007 7:07 pm

It worked for me : I copied kissitpc's smtp.php that had been posted :D and maybe thats the problem because I got the following:

Warning: Cannot modify header information - headers already sent by (output started at /var/www/phpBB2/includes/smtp.php:2) in /var/www/phpBB2/admin/page_header_admin.php on line 143

Warning: Cannot modify header information - headers already sent by (output started at /var/www/phpBB2/includes/smtp.php:2) in /var/www/phpBB2/admin/page_header_admin.php on line 145

Warning: Cannot modify header information - headers already sent by (output started at /var/www/phpBB2/includes/smtp.php:2) in /var/www/phpBB2/admin/page_header_admin.php on line 146

after the script processed the email :cry:

solomondg1
Registered User
Posts: 10
Joined: Sat Apr 21, 2007 5:56 pm

Re: [RC1] BetterSMTP

Post by solomondg1 » Sat Nov 10, 2007 6:58 am

OMG THANK YOU VOID MAIN!!!!!!!!!!!!! YOUR ORIGINAL CODE WORKS PERFECTLY!!!!!!! iv been looking for this for weeks and then i pop in ur code and send a mass email and i get that amazing combination of words - "email sent" WOW!!!!! THANK YOU!!!!!!

pokoko
Registered User
Posts: 16
Joined: Sat Nov 17, 2007 1:10 pm

Re: [RC1] BetterSMTP

Post by pokoko » Thu Nov 29, 2007 11:43 am

i have the forum in awardspace (free) doesn't hace smtp

can i configure this MOD for yahoo or gmail?

ace2ace
Registered User
Posts: 364
Joined: Sat Aug 14, 2004 3:48 pm

Re: [RC1] BetterSMTP

Post by ace2ace » Wed Jan 02, 2008 11:54 pm

BetterSMTP,
what changes did you make to have the google smtp working?
Thanks

DivErTido
Registered User
Posts: 642
Joined: Fri Aug 08, 2003 10:11 pm
Contact:

Re: [RC1] BetterSMTP

Post by DivErTido » Tue Feb 05, 2008 4:29 am

I have installed this mod but I get this:
Server uses Secure Authentication (SSL/TLS) [ help ]
WARNING: This PHP engine cannot use secure authentication!
Make sure you're running PHP version >= 4.3.0 with openssl enabled.
I will now install openssl in my php.
But I really need 4.3.0 PHP version exactly? I have 4.4.4, will not work?
P.S. Please sorry for my poor english...
Legendas Divx

DivErTido
Registered User
Posts: 642
Joined: Fri Aug 08, 2003 10:11 pm
Contact:

Re: [RC1] BetterSMTP

Post by DivErTido » Tue Feb 05, 2008 4:26 pm

Well, tested and working 99% :D
The 1% is because of portuguese characters that is not recognized in the subject field. Any fix for this? :)
P.S. Please sorry for my poor english...
Legendas Divx

Post Reply

Return to “[2.0.x] MODs in Development”