PDA

View Full Version : Include sendemail


qRazor
24/03/2019, 12:55 PM
Hi, I want to use include sendmail and I would need a host. How can I use my web and what I need?

Actual host: geradoresjfs.host22.com/SendEmail.php

bgedition
24/03/2019, 03:22 PM
This can be useful for a simple post request: https://wiki.sa-mp.com/wiki/HTTP
For the endpoint you can simply use this: http://php.net/manual/en/function.mail.php

qRazor
24/03/2019, 03:45 PM
This can be useful for a simple post request: https://wiki.sa-mp.com/wiki/HTTP
For the endpoint you can simply use this: http://php.net/manual/en/function.mail.php
And how can I send emails to different emails?

EDIT: Or the question is how to extract from the database the email of player.

bgedition
24/03/2019, 04:25 PM
You probably will have the player's email stored(probably when they log in) in an enum in the script.
Then you would make a POST request to an endpoint to the PHP script, in that request you would also pass the player's email, the message and the subject.

Edit:
You can use this as an example: https://forum.sa-mp.com/showthread.php?t=351065

qRazor
24/03/2019, 08:16 PM
You probably will have the player's email stored(probably when they log in) in an enum in the script.
Then you would make a POST request to an endpoint to the PHP script, in that request you would also pass the player's email, the message and the subject.

Edit:
You can use this as an example: https://forum.sa-mp.com/showthread.php?t=351065
The email is not delivered... further down the source code:

sendemail.inc
#include <a_http>

#if !defined Function
#define Function::%0(%1) %0(%1); public %0(%1)
#endif
Function::SendMail(EmailTo[],Subject[],Message[],EmailFrom[]) {
new Link[1200];
//format(Link,sizeof(Link),"saveg.ro/sendemail.php?EmailTo=%s&Subject=%s&From=%s&Message=%s",EmailTo,Subject,EmailFrom,Message);
format(Link,sizeof(Link),"saveg.ro/sendemail.php?code=44514&EmailTo=%s&Subject=%s&Message=%s&EmailFrom=%s",EmailTo,Subject,Message,EmailFrom);
for(new c; c < strlen(Link)+1; c++) if(Link[c] == ' ') Link[c] = '+';
HTTP(0, HTTP_POST, Link, "", "");
return 1;
}

sendemail.php
<?php
if (isset($_GET['code'])) { //checks if request from SA:MP server contains code
$code = $_GET['code'];//Redefine just to look better :)
if($code == 44514) { // Compare code from SA:MP request, a.k.a password to avoid spam or unauthorized requests
if (isset($_GET['Message']) && !empty($_GET['Message'])) { //Checks if request from SA:MP server contains messag you want to send
//EmailTo[],Subject[],Message[],EmailFrom[]
$emailto = $_GET['EmailTo'];
$subject = $_GET['Subject'];
$message = $_GET['Message'];//Redefine just to look better :)
$message = str_replace("-"," ",$message);//Replace all - back to blank space as url cant contains blank spaces
mail($emailto, $subject, $message,"From: \"SA:MP server\" <support@saveg.ro>\r\n" ."X-Mailer: PHP/" . phpversion());//Send an email, format: To,Subject,Message,From
echo "Email delivered";//Response message to SA:MP server, so server knows request was valid
}
}
}
?>

EDIT: In gamemode i have:
format(emails, sizeof(emails), "Salutare %s,\nAi primit acest email pentru ca pe serverul rpg.og-times.ro cineva s-a logat dintr-o locatie diferita/de pe un PC diferit pe contul tau.\nDaca tu esti persoana ce s-a logat pe cont, click pe link-ul de mai jos pentru deblocarea contului: key - %s", PlayerInfo[playerid][pNormalName], key2);
SendMail(PlayerInfo[playerid][pEmail], emails, "saveG.ro - Securitate cont / Account security", "support@saveg.ro");

iorp
24/03/2019, 08:35 PM
You can easily use custom plugin for this work, it would be good for server performance

You can also create your own listener so that you can inform players in the game player for the arrival of new email

qRazor
25/03/2019, 02:24 PM
I modified:
HTTP(0, HTTP_POST, Link, "", "");
In this(i gave up on includes and I inserted the function in the gamemode):
HTTP(playerid, HTTP_GET, Link, "", "EmailDelivered");
Because in sendemail.php i use function $_GET. Now I get error 302 HTTP, how can I solve it?
The php script runs I tested it but only in game I get the error.

Function SendEmail:
function SendMail(playerid, EmailTo[], Message[]) {
new Link[500];
format(Link, sizeof(Link), "mydomain.ro/sendemail.php?code=44514&EmailTo=%s&Message=%s", EmailTo, Message);
HTTP(playerid, HTTP_GET, Link, "", "EmailDelivered");
return 1;
}

EDIT: I replaced my web name with mydomain, mydomain.ro is just an example.

qRazor
25/03/2019, 08:45 PM
I have SSL certificate(https) how can I solve this problem?