SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 14/08/2020, 04:37 AM   #1
GeorgeLimit
Big Clucker
 
GeorgeLimit's Avatar
 
Join Date: Mar 2018
Location: Jawa Timur, Indonesia
Posts: 166
Reputation: 0
Default Any help about mailer?

I use HTTP function to my website

Code:
https://mywebsite.com/email/?name=MyName&code=12345&email=myemail@gmail.com
but website response is 400 idk why
__________________

Quote:
That is perfectly fine, I'm just pointing out where you made mistakes what does hearing "good job" get you? Absolutely nothing. You need to hear the problems otherwise you'll keep making the same mistakes

Last edited by GeorgeLimit; 14/08/2020 at 05:22 AM.
GeorgeLimit is offline   Reply With Quote
Old 14/08/2020, 04:44 AM   #2
GeorgeLimit
Big Clucker
 
GeorgeLimit's Avatar
 
Join Date: Mar 2018
Location: Jawa Timur, Indonesia
Posts: 166
Reputation: 0
Default Re: Any help about mailer?

Btw i use PHPMailer no PHP mail func
__________________

Quote:
That is perfectly fine, I'm just pointing out where you made mistakes what does hearing "good job" get you? Absolutely nothing. You need to hear the problems otherwise you'll keep making the same mistakes
GeorgeLimit is offline   Reply With Quote
Old 14/08/2020, 05:50 AM   #3
Kursed
Huge Clucker
 
Kursed's Avatar
 
Join Date: Jan 2015
Posts: 277
Reputation: 35
Default Re: Any help about mailer?

Code:
"mywebsite.com/email.php?name=MyName&code=12345&email=myemail@gmail.com"
__________________
Kursed is online now   Reply With Quote
Old 14/08/2020, 06:06 AM   #4
GeorgeLimit
Big Clucker
 
GeorgeLimit's Avatar
 
Join Date: Mar 2018
Location: Jawa Timur, Indonesia
Posts: 166
Reputation: 0
Default Re: Any help about mailer?

I use index.php thats why i only use ? not index.php?

there's the problem?
__________________

Quote:
That is perfectly fine, I'm just pointing out where you made mistakes what does hearing "good job" get you? Absolutely nothing. You need to hear the problems otherwise you'll keep making the same mistakes
GeorgeLimit is offline   Reply With Quote
Old 14/08/2020, 10:19 AM   #5
TomHarper
Little Clucker
 
TomHarper's Avatar
 
Join Date: Aug 2020
Posts: 38
Reputation: 6
Default Re: Any help about mailer?

Show us some codes. 400 error is a bad request error. That's the HTTP request sent is not properly formatted.

Last edited by TomHarper; 21/08/2020 at 04:56 PM.
TomHarper is offline   Reply With Quote
Old 14/08/2020, 11:23 AM   #6
GeorgeLimit
Big Clucker
 
GeorgeLimit's Avatar
 
Join Date: Mar 2018
Location: Jawa Timur, Indonesia
Posts: 166
Reputation: 0
Default Re: Any help about mailer?

Code:
stock SendPlayerMailCode(playerid, code)
{
    format(format_string, 188, "myweb.com/email/?email=%s&code=%s&username=%s", PlayerInfo[playerid][pMail], code, GetPlayerNameEx(playerid));
    return HTTP(playerid, HTTP_GET, format_string, "", "CheckSendPlayerCode");
}

publics: CheckSendPlayerCode(playerid, response_code, data[])
{
    if(response_code != 200) return SCMF(playerid, COLOR_GREY, "Error %d.", response_code);

	return SCMF(playerid, COLOR_GREEN, "Send");
}
__________________

Quote:
That is perfectly fine, I'm just pointing out where you made mistakes what does hearing "good job" get you? Absolutely nothing. You need to hear the problems otherwise you'll keep making the same mistakes
GeorgeLimit is offline   Reply With Quote
Old 14/08/2020, 11:35 AM   #7
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,843
Reputation: 1693
Default Re: Any help about mailer?

Encode your inputs
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009
Kwarde is offline   Reply With Quote
Old 14/08/2020, 11:48 AM   #8
GeorgeLimit
Big Clucker
 
GeorgeLimit's Avatar
 
Join Date: Mar 2018
Location: Jawa Timur, Indonesia
Posts: 166
Reputation: 0
Default Re: Any help about mailer?

Any example?
__________________

Quote:
That is perfectly fine, I'm just pointing out where you made mistakes what does hearing "good job" get you? Absolutely nothing. You need to hear the problems otherwise you'll keep making the same mistakes
GeorgeLimit is offline   Reply With Quote
Old 14/08/2020, 02:55 PM   #9
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,843
Reputation: 1693
Default Re: Any help about mailer?

The urlencode function: (no idea who originally made it)
pawn Code:
stock urlencode(string[])
{
    new ret[200];
    ret[0] = 0;
    new i = 0;
    new p = 0;
    new s = 0;
    while (string[i] != 0) {
        if  (
                (string[i] >= 'A' && string[i] <='Z')
                || (string[i] >= 'a' && string[i] <='z')
                || (string[i] >= '0' && string[i] <='9')
                || (string[i] == '-')
                || (string[i] == '_')
                || (string[i] == '.')
            ) {
                ret[p] = string[i];
            } else {
                //
                ret[p] = '%';
                p++;
                s = (string[i] % 16); //
                ret[p+1] = (s>9) ? (55+s) : (48+s); // 64 - 9 = 55
                s = floatround((string[i] - s)/16);
                ret[p] = (s>9) ? (55+s) : (48+s); // 64 - 9 = 55
                p++;
            }
        p++;
        i++;
    }
    return ret;
}

Using it:
pawn Code:
format(format_string, 188, "myweb.com/email/?email=%s&code=%s&username=%s", urlencode(PlayerInfo[playerid][pMail]), urlencode(code), urlencode(GetPlayerNameEx(playerid)));
Encoding is only needed when it contains a character any other than:
a-z
A-Z
0-9
- (score)
_ (underscore)
. (dot)

The email contains the @ character, which needs to be encoded(/escaped)
If your code doesn't contain special characters it doesn't need to be encoded.
Usernames may contain characters such as [], (), $ and @ and should be encoded.

If it still occurs then there must be something wrong with the webscript, even though 400 is usually a client caused error:
Quote:
The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
EDIT:
Also make sure that format_string is actually long enough for the url. I don't think it's too short but try printing format_string to the console/server log to see if it's properly formatted.
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009
Kwarde is offline   Reply With Quote
Old 15/08/2020, 01:40 AM   #10
GeorgeLimit
Big Clucker
 
GeorgeLimit's Avatar
 
Join Date: Mar 2018
Location: Jawa Timur, Indonesia
Posts: 166
Reputation: 0
Default Re: Any help about mailer?

Thanks so much +rep
__________________

Quote:
That is perfectly fine, I'm just pointing out where you made mistakes what does hearing "good job" get you? Absolutely nothing. You need to hear the problems otherwise you'll keep making the same mistakes
GeorgeLimit 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
[Ajuda] Mailer Andinho Português/Portuguese 3 20/07/2017 06:01 PM
MAILER Pearson Scripting Help 1 17/11/2016 09:33 PM
[Ajuda] mailer.php Welconha Português/Portuguese 3 12/08/2015 12:04 AM
Mailer osman2571 Scripting Help 0 25/10/2014 07:30 PM
Mailer AroseKhanNiazi Scripting Help 0 01/06/2014 05:41 PM


All times are GMT. The time now is 05:04 PM.


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