fairyoggy Posted December 25, 2019 Posted December 25, 2019 Help! How to implement a script for sending emails? Something like: use in script login and password from e-mail and this email will be send mail on other email.
Motar2k Posted December 25, 2019 Posted December 25, 2019 @slapz0r Check this https://community.multitheftauto.com/index.php?p=resources&s=details&id=11231 1
fairyoggy Posted December 26, 2019 Author Posted December 26, 2019 I don’t understand how it works, can anyone help with this? So that the script code has a username and password from the email and this email will be send mail on other email.
Moderators Patrick Posted December 26, 2019 Moderators Posted December 26, 2019 You need to create a 'email api' on a webserver. And you need to call this api from MTA with fetchRemote.
fairyoggy Posted December 27, 2019 Author Posted December 27, 2019 Can you give me a working example for "email api" ?
Moderators Patrick Posted December 27, 2019 Moderators Posted December 27, 2019 (edited) 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 December 27, 2019 by stPatrick 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now