Jump to content

email script


fairyoggy

Recommended Posts

  • Moderators
1 hour ago, slapz0r said:

Can you give me a working example for "email api" ?

 

PHP Mail sending: https://www.php.net/manual/en/function.mail.php

PHP GET requests: https://www.php.net/manual/en/reserved.variables.get.php

MTA fetchRemote: https://wiki.multitheftauto.com/wiki/FetchRemote

 

PHP CODE

<?php
	if ($_SERVER["REQUEST_METHOD"] != "GET") die("Wrong request method."); // allow only GET requests.

	// READ VALUES FROM URL (the GET request's values)
	if (!isset($_GET["api_key"])) die("Value 'api_key' missing.");
	$api_key = $_GET["api_key"];
	
	if (!isset($_GET["email"])) die("Value 'email' missing.");
	$email	 = $_GET["email"];
	
	if (!isset($_GET["subject"])) die("Value 'subject' missing.");
	$subject = $_GET["subject"];
	
	if (!isset($_GET["message"])) die("Value 'message' missing.");
	$message = $_GET["message"];
	
	
	// CHECK IS API KEY ALLOWED?
	$allowed_api_keys = array("a5BNx7hspRZ5dWJ30", "q9bXRAawamr5K5ab"); // ... list of allow keys
	if (!in_array($api_key, $allowed_api_keys)) die("Wrong api key! (".$api_key.")");
	
	
	// SEND THE EMAIL
	$headers = array(
		'From'		=> '[email protected]', // replace
		'Reply-To'	=> '[email protected]', // replace
		'X-Mailer'	=> 'PHP/' . phpversion()
	);

	if (mail($email, $subject, $message, $headers)) {
		die("Email sent to '".$email."'");
	} else {
		die("Failed to send email '".$email."'");
	}
?>

 

And now, you only need to call this php file with values.

Example: http://YOURDOMAIN.COM/email_api.php?api_key=a5BNx7hspRZ5dWJ30&[email protected]&subject=subject_text&message=message_text

 

And you can call from MTA with fetchRemote:

fetchRemote(
	"http://YOURDOMAIN.COM/email_api.php?api_key=a5BNx7hspRZ5dWJ30&[email protected]&subject=subject_text&message=message_text",
	function (response, errno)
		if (errno == 0) then
			print("fetchRemote success");
		else
			print("fetchRemote failed. (error: "..errno..")");
		end
	end
);

 

Edited by stPatrick
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...