• Resolved southcast

    (@southcast)


    I have finally put together a custom email system utilizing JS and PHP, in which the content within a specific div is mailed to me from my website. I have given the Javascript, Html and php mail script below so you could get a clear idea, how it works. It works just fine. FYI I am no expert on codes and I just copy paste stuff which works for me.

    Please suggest me a few codes to make this system a bit more secure.

    JAVASCRIPT

    <script type="text/javascript">
    jQuery(document).ready(function($) {
        $('#sendEmail').click(function(){
                 $.ajax({
                     type: 'POST',
                     url: 'http://xxxxxxxxxxxxxxx/email.php',
                     data: { content: $('#email-data').html()},
                     success:function(data) {
                            alert('You data has been successfully e-mailed');
                    }
               });
         });
    });
    </script>

    HTML

    <div id="email-data">
        <div id="content">
            some php generated content
        </div>
    </div>
    <a id="sendEmail"> SEND EMAIL</a>

    PHP MAIL CODE :

    <?php
      $to = "someone@somemail.com";
      $subject = "FROM WEBSITE";
      $message = $_POST['content'];
      $headers = "From: company <someotherguy@somecompany.in>" . "\r\n" .
                 "Content-type: text/html" . "\r\n";
      mail($to, $subject, $message, $headers);
    ?>

  • The topic ‘Security suggestion for custom email system made on JS and PHP’ is closed to new replies.