SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 10/12/2010, 08:21 AM   #1
Slice
High-roller
 
Join Date: Mar 2008
Location: Sweden
Posts: 1,831
Reputation: 1607
Default My Mailer Include

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 \"mlr\" & it's sbjct!", "Hll hw r yo? I'm \"writing\" weird simply to test if my mailer script can handle it without any problems. Gt prblm wth tht?" );
}

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;
	}
}

Last edited by Slice; 15/04/2019 at 02:23 PM.
Slice is offline   Reply With Quote
Old 10/12/2010, 08:28 AM   #2
__
Huge Clucker
 
__'s Avatar
 
Join Date: Nov 2010
Location: o359t6lC0u4=
Posts: 232
Reputation: 20
Default Re: My Mailer Include

A lot better, nice one.
__ is offline   Reply With Quote
Old 10/12/2010, 09:11 AM   #3
Gh0sT_
Gangsta
 
Join Date: Sep 2010
Location: Lithuania, Alytus
Posts: 704
Reputation: 0
Default Re: My Mailer Include

Amazing, like always! Thank you so much. ;>
__________________
Includes
Player/Vehicle Control
Entrances system
Gh0sT_ is offline   Reply With Quote
Old 10/12/2010, 12:17 PM   #4
Gavibro
Big Clucker
 
Gavibro's Avatar
 
Join Date: Nov 2010
Location: Afrika
Posts: 54
Reputation: 5
Default Re: My Mailer Include

Yeah,thanks much,now I can flood a mail from sa-mp
just joking,nice script
Gavibro is offline   Reply With Quote
Old 10/12/2010, 12:56 PM   #5
HyperZ
High-roller
 
HyperZ's Avatar
 
Join Date: Aug 2009
Posts: 1,340
Reputation: 66
Default Re: My Mailer Include

Nice Work.
__________________
HyperZ is offline   Reply With Quote
Old 10/12/2010, 03:10 PM   #6
Yagoda
Little Clucker
 
Join Date: Oct 2010
Posts: 22
Reputation: 0
Default Re: My Mailer Include

Very good !!!
Yagoda is offline   Reply With Quote
Old 10/12/2010, 04:11 PM   #7
..
Little Clucker
 
Join Date: Dec 2010
Posts: 9
Reputation: 0
Default Re: My Mailer Include

nice job
.. is offline   Reply With Quote
Old 12/12/2010, 06:20 PM   #8
anonymousx
Big Clucker
 
Join Date: Feb 2010
Location: Argentina
Posts: 146
Reputation: 2
Default Respuesta: My Mailer Include

Nice work man, i gonna use it.
anonymousx is offline   Reply With Quote
Old 12/12/2010, 06:24 PM   #9
nuriel8833
High-roller
 
nuriel8833's Avatar
 
Join Date: Jun 2009
Location: Israel
Posts: 1,157
Reputation: 16
Default Re: My Mailer Include

Great Job!
__________________
Back to forums
Although I am not scripting much,only my gamemode on my free time

My works:
80.179.219.89:7778
[Tutorial] Kills Table BonusLast.fm
nuriel8833 is offline   Reply With Quote
Old 12/12/2010, 07:10 PM   #10
WillyP
High-roller
 
WillyP's Avatar
 
Join Date: Jul 2010
Location: England
Posts: 2,027
Reputation: 63
Default Re: My Mailer Include

Sweet, but can someone test it for me?
__________________
once average now terrible
WillyP is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tool/Web/Other] [WEB | SCRIPT] In-Game Mailer lolumadd Filterscripts 23 28/08/2011 12:41 PM


All times are GMT. The time now is 08:12 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.