• Resolved talon77

    (@talon77)


    I am setting up a basic email form. I do not want to use a mail plugin. I am trying build my own mail form using HTML and PHP. I have my html code on the page and it displays correctly. I have downloaded the Shortcode Exec PHP plugin that allows users to run PHP and have inserted, named, and saved my PHP code. My question is how do I reference this in my HTML?

    A Typical HMTL form tag would be coded something like this:

    <form action="sendMail.php" method="post" enctype="text/plain">

    What I am doing is this:
    <form action="[Email]" method="post" enctype="text/plain">
    where [Email] is the name that I have given my shortcode. The odd thing is that this worked once and has not worked since. Any ideas? How you would you guys make reference to the php code? If not inside the form tag, where would I add it?

    The following is my HTML:

    <form action="[Email]" method="post" enctype="text/plain">
    <input id="check1" type="checkbox" name="check1" />Print Design
    <input id="check2" type="checkbox" name="check2"/>Logo Design
    <input id="check3" type="checkbox" name="check3"/>Web Design
    </form>

    The following is my PHP:

    $from="doNotReply@widdle.com";
    $check1=$_REQUEST['check1'];
    $check2=$_REQUEST['check2'];
    $check3=$_REQUEST['check3'];
    
    mail("talon77email@talon77.com", "Form Submission Notice", $check1 , "From: $from");
    print "Your form has been submitted";

Viewing 5 replies - 1 through 5 (of 5 total)
  • wpismypuppet

    (@wordpressismypuppet)

    If the PHP code is on the same page as the form, then simply use:

    <form action="" method="post" enctype="text/plain">

    add a submit button to the form, or at least a hidden field set to 1:

    <input type="submit" name="action" value="Send Email" />

    Then wrap all your PHP around an if statement to check if you submit button, or hidden variable set to 1, exists:

    <?php
        if( isset( $_POST['action'] ) ) {
            $from="doNotReply@widdle.com";
            $check1=$_POST['check1'];
            $check2=$_POST['check2'];
            $check3=$_POST['check3'];
    
            mail("talon77email@talon77.com", "Form Submission Notice", $check1 , "From: $from");
            print "Your form has been submitted";
        }
    ?>

    If your code is not on the same page as the form, you’ll need to submit the form and get directed to the page that does contain that code. What is the reason for the shortcode, out of curiosity?

    Thread Starter talon77

    (@talon77)

    Ok I will try what you have and let you know how it goes. I have a submit button but I did not include it in what I copied from my HTML code. The reason I am using shortcode is because for some reason I scripts that I put directly into my code via the “text tab” runs very strangely in wordpress for some reason. I know because I have copied out the code and run it directly onto my browser from my computer’s desktop and everything works fine. But for some reason through wordpress buttons stop running the functions they are supposed to run, elements that should be hidden by default are visible, etc

    wpismypuppet

    (@wordpressismypuppet)

    WordPress editor has a way of doing strange things to code. Typically in a situation like this I would either use a form plugin, or simply create a page template where I could put my PHP code and not have to worry about corruption. The only reason I suggested what I did is because of your PHP plugin you are using. Let me know how it goes.

    Thread Starter talon77

    (@talon77)

    I am testing it now, still there seems to be something wrong. What I do not understand is why the code worked once and then simply did not work anymore before even my changing anything. This is the first time that I have encountered this

    Thread Starter talon77

    (@talon77)

    Eureka! The problem must have been my email! I logged out of it and logged back in some minutes later and their were over 10 messages in my inbox from my email form. The code in the initial post works.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Email form and PHP shortcode’ is closed to new replies.