-1

I've been learning PHP, I created an email sending script as below:

application/x-httpd-php index.php ( HTML document text )

<html>
    <head>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <meta name="viewport" content="width=device-width, initial-scale=1">
            <title>Fake / Spoof Email Sender Online Script</title>
        <style>
        body {
    background: #F8A434;
    font-family: 'Lato',sans-serif;
    color: #FDFCFB;
    text-align: center;
    overflow: hidden;
}

td{
    padding: 5px;
}

input{
color: #222;
}

textarea {
    overflow: auto;
    padding: 5px;
}

button, input, select, textarea {
    padding: 5px;
    text-indent: 3%;
       color: #222;
}
        </style>
    </head>
    <body>
    <div id="container">
    <h2> Send Anonymous Email With Fake Email Sender</h2>
        <form method="post">
            <table>
              <div class="row">
                    <tr>
                            <td>Subject:</td>
                            <td><input type="text" name="txt1" placeholder="Hello"></td>
                    </tr>
                    </div>
                      <div class="row">
                    <tr>
                    <div class="col-sm-4">
                            <td>From E-Mail:</td>
                            <td><input type="email" name="txt6" placeholder="example@gmail.com"></td>
                            </div>
                    </tr>
                    </div>
                      <div class="row">
                    <tr>
                    <div class="col-sm-4">
                            <td>To:</td>
                            <td><input type="email" name="txt3" placeholder="example@gmail.com"></td>
                    </div>
                    </tr>
                    </div>
                      <div class="row">
                    <tr>
                    <div class="col-sm-4">
                            <td>Your Message</td>
                            <td><textarea name="txt4"></textarea></td>
                    </div>
                    </tr>
                    </div>  <div class="row">
                    <tr>
                    <div class="col-sm-4">
                            <td></td>

                            <td><input type="submit" name="send" value="Send Spoofed Email" class="btn btn-success"></td>

                            <tr>
                            <td></td>
                            <td><input type="reset" name="send" value="Reset" class="btn btn-success"></td>
                            </tr>
                    </div>
                    </tr>
                    </div>
            </table>
        </form>
        </div>

        <?php
                if(isset($_POST['send']))
                {
                        $name=$_POST['txt1'];
                        $email=$_POST['txt6'];
                        $query=$_POST['txt4'];
                        $to=$_POST['txt3'];

                        $msg=$query;

                        $subject=$name;
                        $header='From:'.$email;

                        if(mail($to,$subject,$msg,$header))
                        {
                            echo "Mail Sent";
                        }


                }
        ?>
    </body>
</html>

Now, how can I store the messages, which are sent by this script? Can anyone give me a hint, or modify this code according to my requirements?

jkucharovic
  • 4,214
  • 1
  • 31
  • 46
Arsh Arora
  • 61
  • 1
  • 10

1 Answers1

-1

You will need to use something like this MySQL:

# Create connection
$conn = new mysqli("localhost:3306", 'root', $pass,'dbname');

# If the database won't connect
if($conn->connect_error) {
die("<mark>DB Connection failed: " . $conn->connect_error ."</mark>");}

$q = "INSERT INTO x (name,email,query,to)

VALUES ('".$_POST['txt1']."', '".$_POST['txt6']."','".$_POST['txt4']. "','".$_POST['txt3']."')";
$conn->query($q);$conn->exec($q);$conn->close();

Keep in mind that you'll either need to sanitise the variables, or use prepare statements.

Aeron R
  • 75
  • 8
  • 2
    Never use user input directly in an SQL string like this, unless you want your users to have complete control over your database. Please see https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?r=SearchResults – IMSoP Jun 26 '21 at 10:07
  • Yep. I forgot to mention that. Thanks. – Aeron R Jun 27 '21 at 02:57