health

Technology

business posts

Creating a PHP Fake-Mailer!

There is a function in PHP called mail(). The Normal Use is to send a message to an e-mail with a subject. However, you can also configure the headers!
The headers are really useful for a Mailer. You can pretend to be an Other Person (ex. I can send mail as Bill Gates from microsoft.com!), or configure the Mail Client you use (iPhone Mail, Thunderbird…)
I think that you should start creating a Fake-Mailer in PHP, so let’s do it!

HTML Form:

So, we need first to create an HTML Form so as to enter the Data. Create a file named “index.html” and type these:
<form method=”GET” action=”send.php”>
<p>To: <input type=”text” name=”to” /></p>
<p>From-Name: <input type=”text” name=”name” /></p>
<p>From-Email: <input type=”text” name=”from” /></p>
<p>Content-Type: <input type=”radio” name=”con” value=”p” /> Plain-Text || <input type=”radio” value=”h” name=”con” /> HTML</p>
<p>Subject: <input type=”text” name=”subject” /></p>
<p>Content:</p>
<textarea name=”content” rows=”30″ cols=”60″ class=”textm”>Your E-Mail Here…</textarea>
<p>
<input type=”submit” value=”Send E-Mail” ></p>
</form>

PHP Form:

We also need a PHP Form! Create a new File called “send.php” and enter these:
<?php
$to=$_REQUEST[‘to’];
$subject=$_REQUEST[‘subject’];
$name=$_REQUEST[‘name’];
$from=$_REQUEST[‘from’];
$type=$_REQUEST[‘con’];
$content=$_REQUEST[‘content’];
if(isset($to) && isset($name) && isset($from) && isset($content) && isset($type)){
           if($type == ‘h’){
                      $type=’text/html’;
           }else{
                      $type=’text/plain’;
           }
mail($to,$subject,$content,”From:$name<$from>\r\nContent-Type:$type”);
echo(“<p style=”color:green”>E-Mail Sent!</p>”);
}
else{
         echo(“<p style=”color:red”>E-Mail NOT Sent!</p>”);
}
?>

Explanation:

HTML Form:
If you know some  HTML, you know this is a Page of Inputs that you can enter text. It has also two Radio Buttons so that you select whether you want your message to be Plain Text or HTML.
The “name” attributes of each input are vital, since the PHP “gets” their value by these unique names!
PHP Form:
At the PHP Form, we first store in Variables the Values of the Inputs of the HTML Page. In this way, we can handle them more easily!
Then, we check if all the inputs are entered using the isset() function. If they are set, it proceeds and checks what is the value of the Radio Buttons, Plain Text or HTML.
After, it sends the E-Mail using the mail() function and displays a Green E-Mail Sent!
However, If one input is not entered, the Mail Will not be sent, and a E-Mail NOT Sent message will be displayed!

You must install PHP to your Machine, if you want to run it locally! Otherwise, you should create an Account to a Web Hosting Service and Upload the Two Files there!


I hope the Tutorial is easily-readable for everyone!

No comments: