SA-MP Forums Archive
SMTP setting help to send email from game - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SMTP setting help to send email from game (/showthread.php?tid=588214)



SMTP setting help to send email from game - Kutuy19 - 06.09.2015

I'm trying to make a verification email system, where the player will be asked to sign up for e-mail and the game will send a verification code to the email. The problem that occurs is, the verification code is not sent to a predetermined email. What is wrong? I have been using tools such as RegEx v0.2.1, and...

mailer.php:
Код:
<?php
	ini_set( 'html_errors', false );
	
	if ( empty( $_POST[ 't' ] ) || empty( $_POST[ 'f' ] ) || empty( $_POST[ 'n' ] ) || empty( $_POST[ 's' ] ) || empty( $_POST[ 'm' ] ) )
		die( 'Error: Missing parameters.' );
	
	mail(
		$_POST[ 't' ],
		utf8_encode( $_POST[ 's' ] ),
		$_POST[ 'm' ],
		implode(
			"\r\n",
			array
			(
				'From: "' . addslashes( $_POST[ 'f' ] ) . "\" <{$_POST[ 'n' ]}>",
				"Reply-To: {$_POST['f']}",
				"X-Mailer: PHP/" . phpversion( ),
			)
		)
	);
?>
mailer.inc
Код:
#include <a_samp>
#include <a_http>

#if ( !defined MAILER_MAX_MAIL_SIZE )
	#define MAILER_MAX_MAIL_SIZE  (1024)
#endif

#if ( !defined MAILER_URL )
	#error Please define MAILER_URL before including the mailer include.
#endif

stock SendMail( const szReceiver[ ], const szSenderMail[ ], const szSenderName[ ], const szSubject[ ], const szMessage[ ] )
{
	new
		szBuffer[ MAILER_MAX_MAIL_SIZE ] = "t=",
		iPos    = strlen( szBuffer ),
		iLength = strlen( szReceiver )
	;
	
	memcpy( szBuffer, szReceiver, iPos * 4, ( iLength + 1 ) * 4 );
	
	StringURLEncode( szBuffer[ iPos ], 1024 - iPos );
	
	strcat( szBuffer, "&f=" );
	
	iPos    = strlen( szBuffer );
	iLength = strlen( szSenderName );
	
	memcpy( szBuffer, szSenderName, iPos * 4, ( iLength + 1 ) * 4 );
	
	StringURLEncode( szBuffer[ iPos ], 1024 - iPos );
	
	strcat( szBuffer, "&n=" );
	
	iPos    = strlen( szBuffer );
	iLength = strlen( szSenderMail );
	
	memcpy( szBuffer, szSenderMail, iPos * 4, ( iLength + 1 ) * 4 );
	
	StringURLEncode( szBuffer[ iPos ], 1024 - iPos );
	
	strcat( szBuffer, "&s=" );
	
	iPos    = strlen( szBuffer );
	iLength = strlen( szSubject );
	
	memcpy( szBuffer, szSubject, iPos * 4, ( iLength + 1 ) * 4 );
	
	StringURLEncode( szBuffer[ iPos ], 1024 - iPos );
	
	strcat( szBuffer, "&m=" );
	
	iPos    = strlen( szBuffer );
	iLength = strlen( szMessage );
	
	memcpy( szBuffer, szMessage, iPos * 4, ( iLength + 1 ) * 4 );
	
	StringURLEncode( szBuffer[ iPos ], 1024 - iPos );
	
	HTTP( 0xD00D, HTTP_POST, MAILER_URL, szBuffer, "OnMailScriptResponse" );
}

forward OnMailScriptResponse( iIndex, iResponseCode, const szData[ ] );
public  OnMailScriptResponse( iIndex, iResponseCode, const szData[ ] )
{
	if ( szData[ 0 ] )
		printf( "Mailer script says: %s", szData );
}

stock StringURLEncode( szString[ ], iSize = sizeof( szString ) )
{
	for ( new i = 0, l = strlen( szString ); i < l; i++ )
	{
		switch ( szString[ i ] )
		{
			case '!', '(', ')', '\'', '*',
			     '0' .. '9',
			     'A' .. 'Z',
			     'a' .. 'z':
			{
				continue;
			}
			
			case ' ':
			{
				szString[ i ] = '+';
				
				continue;
			}
		}
		
		new
			s_szHex[ 8 ]
		;
		
		if ( i + 3 >= iSize )
		{
			szString[ i ] = EOS;
			
			break;
		}
		
		if ( l + 3 >= iSize )
			szString[ iSize - 3 ] = EOS;
		
		format( s_szHex, sizeof( s_szHex ), "%02h", szString[ i ] );
		
		szString[ i ] = '%';
		
		strins( szString, s_szHex, i + 1, iSize );
		
		l += 2;
		i += 2;
		
		if ( l > iSize - 1 )
			l = iSize - 1;
	}
}
Apart from that i also have uploaded mailer.php to my web hosting and on GM I have entered ...
Код:
#define MAILER_URL "mydomain.co.id/mailer.php"
#define SMTP_HOST "mydomain.co.id"
#define SMTP_PORT 25
I have also made a record on my web hosting ...
Код:
smtp.mydomain.co.id and i made a address to my VPS IP
In addition I have also been set up "Additional Hosts that send mail for your domains (A)" in the web hosting control panel and directed me to my VPS IP
Here is the command I use to try to send email ...
Код:
CMD:emailtest(playerid, params[])
{
	SendMail("myemail@gmail.com", "myServer@noreply.com", "Verify", "Verify", "Test email system");
	SendClientMessage(playerid, COLOR_GRAD1, "Email sent.");
	return 1;
}