[Include] My Mailer Include
#1

Hey,
I noticed there are a couple of functions for sending e-mails on the forums and none of them really work properly (no offence).
This, I believe, should be able to handle most charsets (I'm not sure about multi-byte, please let me know how it goes).
It can handle quotes, slashes, special characters, etc.
It also runs relatively fast:
Code:
Bench for SendMail: executes, by average, 32 times/ms.
That doesn't mean you should send mails 32 times in a millisecond!

Usage
PHP Code:
SendMailto[], sender_email[], sender_name[], subject[], message[] ); 
Example
Create a filterscript with the contents below and load it.
pawn Code:
#define MAILER_URL "my-server.com/mailer.php" // This has to be defined BEFORE you include mailer.

#include <mailer>

public OnFilterScriptInit( )
{
    SendMail( "your.email@here.ok", "roleplay.server@example.com", "Roleplay \"Server\"", "My \"mепlлr\" & it's sьbjйct!", "Hиllц hцw еrл yoь? I'm \"writing\" weird simply to test if my mailer script can handle it without any problems. Gцt е prуblлm wпth thдt?" );
}
Download
Put mailer.inc in your pawno\include folder and upload mailer.php to a web server that has PHP (you may need to configure it's SMTP server).

mailer.php:
PHP Code:
<?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:
Code:
#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;
	}
}
Reply


Messages In This Thread
My Mailer Include - by Slice - 10.12.2010, 07:21
Re: My Mailer Include - by __ - 10.12.2010, 07:28
Re: My Mailer Include - by Gh0sT_ - 10.12.2010, 08:11
Re: My Mailer Include - by Gavibro - 10.12.2010, 11:17
Re: My Mailer Include - by HyperZ - 10.12.2010, 11:56
Re: My Mailer Include - by Yagoda - 10.12.2010, 14:10
Re: My Mailer Include - by .. - 10.12.2010, 15:11
Respuesta: My Mailer Include - by anonymousx - 12.12.2010, 17:20
Re: My Mailer Include - by nuriel8833 - 12.12.2010, 17:24
Re: My Mailer Include - by WillyP - 12.12.2010, 18:10
Re: My Mailer Include - by Slice - 12.12.2010, 18:15
Re: My Mailer Include - by WillyP - 12.12.2010, 18:17
Re: My Mailer Include - by Haji - 12.12.2010, 18:25
Re: My Mailer Include - by IstuntmanI - 12.12.2010, 18:41
Re: My Mailer Include - by Nibblet - 16.12.2010, 13:58
Re: My Mailer Include - by r3k1lLz_ - 24.12.2010, 04:03
Re: My Mailer Include - by Mauzen - 13.01.2011, 19:22
Re: My Mailer Include - by Kwarde - 28.01.2011, 13:02
Re: My Mailer Include - by Slice - 28.01.2011, 13:11
Re: My Mailer Include - by Kwarde - 28.01.2011, 13:35
Re: My Mailer Include - by Miguel - 28.01.2011, 17:08
Re : Re: My Mailer Include - by Stormz - 03.06.2011, 13:41
Re : My Mailer Include - by Stormz - 03.06.2011, 14:26
Re: My Mailer Include - by Shelby - 05.07.2011, 01:13
Re: My Mailer Include - by Slice - 05.07.2011, 06:12
Re: My Mailer Include - by Lorenc_ - 05.07.2011, 12:26
Re: My Mailer Include - by Calgon - 05.07.2011, 12:52
Re: My Mailer Include - by Shelby - 05.07.2011, 15:06
Re: My Mailer Include - by Phanto90 - 08.07.2011, 08:16
AW: My Mailer Include - by dUDALUS - 17.08.2011, 17:48
Re: My Mailer Include - by Ronaldo_raul™ - 17.08.2011, 17:52
Re: My Mailer Include - by Scenario - 18.08.2011, 04:07
Re: My Mailer Include - by Lorenc_ - 18.08.2011, 09:21
Re: My Mailer Include - by Scenario - 18.08.2011, 18:26
Re: My Mailer Include - by Scenario - 19.08.2011, 12:59
Re: My Mailer Include - by AndreT - 19.08.2011, 13:04
Re: My Mailer Include - by Scenario - 19.08.2011, 13:09
Re: My Mailer Include - by AndreT - 19.08.2011, 13:48
Re: My Mailer Include - by Scenario - 19.08.2011, 13:52
Re: My Mailer Include - by AndreT - 19.08.2011, 13:59
Re: My Mailer Include - by Scenario - 19.08.2011, 14:03
Re: My Mailer Include - by Scenario - 20.08.2011, 18:45
Re: My Mailer Include - by Slice - 21.08.2011, 01:29
Re : My Mailer Include - by Brian Turner - 31.08.2011, 13:03
Re: Re : My Mailer Include - by Slice - 01.09.2011, 09:04
Re: My Mailer Include - by Lefon - 01.09.2011, 12:48
Re: My Mailer Include - by Slice - 01.09.2011, 13:03
Re: My Mailer Include - by Lefon - 01.09.2011, 13:08
Re: My Mailer Include - by FireCat - 01.09.2011, 13:18
Re : Re: Re : My Mailer Include - by Brian Turner - 03.09.2011, 13:27
Re: My Mailer Include - by Slice - 14.10.2012, 10:06
Re: My Mailer Include - by NoahF - 14.10.2012, 10:15
Re: My Mailer Include - by Lordzy - 14.10.2012, 10:25
Re: My Mailer Include - by Maniek - 14.10.2012, 18:37
Re: My Mailer Include - by Slice - 15.10.2012, 06:43
Re: My Mailer Include - by zSuYaNw - 15.10.2012, 06:59
AW: My Mailer Include - by BiosMarcel - 15.10.2012, 08:04
Re: My Mailer Include - by Marcuse - 14.12.2012, 07:22
Re: My Mailer Include - by Plovix - 14.12.2012, 11:07
Re: My Mailer Include - by Marcuse - 14.12.2012, 14:07
Re: My Mailer Include - by Lordzy - 10.02.2013, 09:48
Respuesta: My Mailer Include - by oOFotherOo - 10.02.2013, 10:34
Re: My Mailer Include - by DiGiTaL_AnGeL - 08.03.2013, 20:55
Re: My Mailer Include - by MattSlater - 14.03.2013, 16:50
Re: My Mailer Include - by Slice - 14.03.2013, 17:07
Re: My Mailer Include - by MattSlater - 14.03.2013, 18:12
Re: My Mailer Include - by DiGiTaL_AnGeL - 14.03.2013, 18:15
Re: My Mailer Include - by F96 - 27.04.2013, 06:38
Re: My Mailer Include - by andreasbleck - 17.08.2013, 21:37
Re: My Mailer Include - by Slice - 18.08.2013, 08:58
Re: My Mailer Include - by Kar - 14.05.2014, 01:06
Re: My Mailer Include - by biker122 - 15.09.2014, 07:07
Re: My Mailer Include - by PawnoQ - 22.06.2015, 21:36
Re: My Mailer Include - by Flashhiee - 28.06.2015, 12:04
Re: My Mailer Include - by bocaraton - 24.07.2015, 21:44
Re: My Mailer Include - by dzo4emkd - 23.12.2015, 18:23
Re: My Mailer Include - by ScIrUsna - 17.03.2016, 04:26
Re: My Mailer Include - by itsCody - 17.03.2016, 04:38
Re: My Mailer Include - by ScIrUsna - 17.03.2016, 05:04
Re: My Mailer Include - by iKevin - 17.03.2016, 05:57
Re: My Mailer Include - by kristo - 17.03.2016, 16:19
Re: My Mailer Include - by Macmilan - 17.08.2016, 16:06
Re: My Mailer Include - by Evocator - 17.08.2016, 21:28
Re: My Mailer Include - by MerryDeer - 13.02.2017, 17:21
Re: My Mailer Include - by addys1 - 20.05.2017, 10:33
Re: My Mailer Include - by Bussyman - 10.08.2017, 16:28
Re: My Mailer Include - by Barnwell - 10.08.2017, 16:44
Re: My Mailer Include - by pulsare - 07.12.2017, 17:42
Re: My Mailer Include - by [BOPE]Seu._.Madruga - 05.10.2018, 20:55
Re: My Mailer Include - by playstores - 19.10.2018, 09:23

Forum Jump:


Users browsing this thread: 2 Guest(s)