10.12.2010, 07:21
(
Last edited by Slice; 15/04/2019 at 01:23 PM.
)
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:
That doesn't mean you should send mails 32 times in a millisecond!
Usage
Example
Create a filterscript with the contents below and load it.
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:
mailer.inc:
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.
Usage
PHP Code:
SendMail( to[], sender_email[], sender_name[], subject[], message[] );
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?" );
}
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( ),
)
)
);
?>
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; } }