php - Javascript Form Submit with Email Action? - Stack Overflow

I need make this form send me a email like a contact form:Script code:<script type="textjavasc

I need make this form send me a email like a contact form:

Script code:

<script type="text/javascript">
        $(document).ready(function(){

            $("#contactLink").click(function(){
                if ($("#contactForm").is(":hidden")){
                    $("#contactForm").slideDown("slow");
                }
                else{
                    $("#contactForm").slideUp("slow");
                }
            });

        });

        function closeForm(){
            $("#messageSent").show("slow");
            setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 2000);
       }
       </script>

HTML CODE:

   <div class="box">
        <div id="contactFormContainer">
            <div id="contactForm">
                <fieldset>
                    <label for="Name">Nome: </label>
                    <input id="name" type="text" />
                    <label for="Telefone">Telefone Fixo: </label>
                    <input type="text" id="phone" maxlength="15" onkeypress="Mascara(this);" />
                    <label for="Message">Assunto:</label>
                    <textarea id="Message" rows="3" cols="20"></textarea>
                    <input id="sendMail" type="submit" name="submit" onclick="closeForm()" />           
                    <span id="messageSent">Sua solicitação foi enviada  sucesso, por favor, aguarde...</span>
               </fieldset>
            </div>
            <div id="contactLink"></div>
        </div>

When click and close the form i need send me a email with the content of form, how to? Some idea? thanks!

I need make this form send me a email like a contact form:

Script code:

<script type="text/javascript">
        $(document).ready(function(){

            $("#contactLink").click(function(){
                if ($("#contactForm").is(":hidden")){
                    $("#contactForm").slideDown("slow");
                }
                else{
                    $("#contactForm").slideUp("slow");
                }
            });

        });

        function closeForm(){
            $("#messageSent").show("slow");
            setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 2000);
       }
       </script>

HTML CODE:

   <div class="box">
        <div id="contactFormContainer">
            <div id="contactForm">
                <fieldset>
                    <label for="Name">Nome: </label>
                    <input id="name" type="text" />
                    <label for="Telefone">Telefone Fixo: </label>
                    <input type="text" id="phone" maxlength="15" onkeypress="Mascara(this);" />
                    <label for="Message">Assunto:</label>
                    <textarea id="Message" rows="3" cols="20"></textarea>
                    <input id="sendMail" type="submit" name="submit" onclick="closeForm()" />           
                    <span id="messageSent">Sua solicitação foi enviada  sucesso, por favor, aguarde...</span>
               </fieldset>
            </div>
            <div id="contactLink"></div>
        </div>

When click and close the form i need send me a email with the content of form, how to? Some idea? thanks!

Share Improve this question edited Aug 11, 2013 at 12:46 Lightness Races in Orbit 386k77 gold badges666 silver badges1.1k bronze badges asked Aug 11, 2013 at 12:42 Isleno IturielIsleno Ituriel 1131 gold badge1 silver badge6 bronze badges 3
  • does your closeForm() function works, it looks a little bit weird for me. – Tzu ng Commented Aug 11, 2013 at 12:45
  • you need some kind of backend solution to send an email 100% reliable, i.e. some Ruby/PHP/Node.JS/Script which sends the email. There is a construction with "mailto:" in HTML, but this is neither professional nor does it always work. – herrjeh42 Commented Aug 11, 2013 at 12:48
  • Yes Vdt, works perfectly but i just don't know how to add a function to email me when the closeForm() function is activated. Sometime ago i saw something like a fuction to call a page, this probably can solve my problem – Isleno Ituriel Commented Aug 11, 2013 at 12:51
Add a ment  | 

2 Answers 2

Reset to default 2

Firstly i can't see the form tags in your code. According to me you're doing this wrong and i'm sure many of our friends on stack will agree too.

Your question suggests that you basically want to receive an email with the data submitted through the form. Why don't you try the below method.

HTML

<form action="mail.php" method="POST">

 <input type="text" name="fname"></input>

 <input type="text" name="lname"></input>

 <button>SUBMIT</button>

</form>

PHP

<?php
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];

$to = "[email protected]";
$subject = "Hello World";
$message = "Firstname: $firstname \n\n Lastname: $lastname";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

The above example is the most simplest method of sending an email. You can go advance by adding more header information and graphically formatting the email.

Go through these tutorials if you get confused.

http://www.w3schools./php/php_mail.asp

http://www.phpeasystep./phptu/8.html

And since you mentioned that you want to perform the task via javascript you can try submitting the form via ajax, refer the below tutorials

http://teachingyou/php/simple-php-contact-form-using-ajax/

http://www.sitepoint./forums/showthread.php?1055068-Send-PHP-email-using-jQuery-AJAX

Since you've tagged the question php, have a look at php's mail function. http://php/manual/en/function.mail.php

$to = '[email protected]';
$subject = 'Contact Form';
$message = '...' //concatenate the $_POST (or $_GET) variables to create this message

mail($to, $subject, wordwrap($message, 70, "\r\n");

This function requires that your server has a properly configured to send mail - see the php documentation for requirements: http://www.php/manual/en/mail.requirements.php

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745254752a4618888.html

相关推荐

  • php - Javascript Form Submit with Email Action? - Stack Overflow

    I need make this form send me a email like a contact form:Script code:<script type="textjavasc

    7小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信