TRiLeZ
2009-07-10 10:59:19
SCAR-PHP Emailer
Over the past 24 hours, I have thought of a really usefull function to make. It could email you whenever you want it to. For example: when a script your using finishes and your not at the computer, SCAR would email the person using the script. If you had a cell that had email, you could read the message and be like oh, the script has finished, lets see why and start it up again. This function would be so usefull and I decided to build it and here it is:
You can customize this email message to whatever you want. You can change:
- The Person Recieving The Email.. of Course
- The Subject
- The Message
- The Sender's Email :eek:
- The Sender's Name :eek:
To start off, you will have to have a webhoster with PHP built in.
If you dont have one just search up free webhosting or something.
Here is my source code for the SCAR-PHP Emailer:
<?php
if (isset($_POST['email']) && isset($_POST['message']) && isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['sender']))
{
$MyEmail = $_POST['email'];
$EmailMessage = $_POST['message'];
$SenderName = $_POST['name'];
$EmailSubject = $_POST['subject'];
$SenderEmail = $_POST['sender'];
$Headers = "From: {$SenderName} <{$SenderEmail}>";
if (empty($email))
{
echo "Error";
} else {
exit;
}
}
?>
<form method="post" action="<?=mail($MyEmail,$EmailSubject,$EmailMessage,$Headers);?>">
<input type="hidden" name="email" value="N/A" />
<input type="hidden" name="message" value="N/A" />
<input type="hidden" name="name" value="N/A" />
<input type="hidden" name="subject" value="N/A" />
<input type="hidden" name="sender" value="N/A" />
</form>
Remember to save that as a .php :p
Now the SCAR function to send the email:
{*******************************************************************************
function SendEmail(MyEmail, Subject, EmailMessage, SenderEmail, SenderName, Website: string): Boolean;
By: TRiLeZ
Description: Sends an email using PHP and SCAR.
*******************************************************************************}
function SendEmail(MyEmail, Subject, EmailMessage, SenderEmail, SenderName, Website: string): Boolean;
var
Email : string;
Client : Integer;
begin
Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
Wait(20);
AddPostVariable(Client, 'email', MyEmail);
AddPostVariable(Client, 'message', EmailMessage);
AddPostVariable(Client, 'name', SenderName);
AddPostVariable(Client, 'subject', Subject);
AddPostVariable(Client, 'sender', SenderEmail);
Email := PostHTTPPageEx(Client, Website);
FreeHTTPClient(Client);
if (Email > '') then Result := true
else
begin
Result := false;
Writeln('Emailing User Failed!');
end;
end;
How do you send the email with that? Heres how:
Call: SendEmail('', '','', '', '', '');
Heres how you would fill that ^ in:
SendEmail('myemail@domain.com', 'SUBJECT', 'MESSAGE', 'SenderEmail', 'SenderName', 'website@domain.com');
Build this in with your scripts you make and they will kick ass :D
Remember to use constants to make things easier for the script user.
Just to let you know, SCAR will ask the script user if they want to allow SCAR to connect to the website, so if they arent there, they wont get their email until they allow the connection, so try to connect to your website and tell the script users to always allow connection to that site.
For your script, you could modify the PHP file and my function so the message, subject, sender and whatever is in the PHP file.
I think thats about it :spot:
Please give comments and suggestions. Feel free to ask questions and give rep :)