0

I have advanced work on my Wordpress plugin, now I need to add wp_mail(). I read this tutorial https://www.sitepoint.com/build-your-own-wordpress-contact-form-plugin-in-5-minutes/ and this tutorial work but not in my plugin.

When I use many echo all form is split apart so I cannot just write ' . esc_url( $_SERVER['REQUEST_URI'] ) . ' I used <?php echo ?> and ${}. Let give me support to my plugins work well.


echo 
    '<form action=" " method="post">
    <div id="sendmail" class="sandmail" style="display:none;">
       <h2 id="form-h1" style="color:white; background-color: #ae4a84;">Formularz kontaktowy</h2>
                
                <input id="ea-name" name="ea-name" placeholder="Imię" class="form-control" 
                pattern="[a-zA-Z0-9 ]+"  />
        <input id="ea-email" placeholder="Email" name="ea-email"   class="form-control" />
        <input id="ea-subject" placeholder="Temat" name="ea-subject" class="form-control" pattern="[a-zA-Z ]+"    />
        <textarea class="form-control textarea" name="ea-body" id="ea-body" placeholder="Treść"  >  
        </textarea> 
        <div class="btn-order">
           <input type="button" id="sendMail" class="btn-second" value="Wyślij" name="ea-submitted"  >
           <input type="button"  value="Wróć" id="btn2" class=" btn-primary"></div>
        </form>'

and php


function deliver_mail() {

    // if the submit button is clicked, send the email
    if ( isset( $_POST['ea-submitted'] ) ) {

        // sanitize form values
        $name    = sanitize_text_field( $_POST["ea-name"] );
        $email   = sanitize_email( $_POST["ea-email"] );
        $subject = sanitize_text_field( $_POST["ea-body"] );
        $message = esc_textarea( $_POST["ea-message"] );

        // get the blog administrator's email address
        $to = "@gmail.com";

        $headers = "From: $name <$email>" . "\r\n";

        // If email has been process for sending, display a success message
        if ( wp_mail( $to, $subject, $message, $headers ) ) {
            echo '<div>';
            echo '<p>Dziękujemy za wypełnienie zgłoszenia</p>';
            echo '</div>';
        } else {
            echo 'Pojawił się nieoczekiwany bład';
        }
    }
}

function cf_shortcode() {
    ob_start();
    deliver_mail();
    html_section();

    return ob_get_clean();
} 

all is in main plugin php file.

5
  • What is your question?
    – kero
    Commented Feb 2, 2022 at 14:02
  • What and how should I do to wp_mail() work in my plugin properly? Where is solution to my state... Commented Feb 2, 2022 at 14:04
  • You can see the documentation of wp_mail() here. I see in your code that you're already calling it - what is happening? Do you see any errors (enable debugging!)? Does the mail get sent?
    – kero
    Commented Feb 2, 2022 at 14:06
  • Finally, I handle it. Commented Feb 2, 2022 at 15:06
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Feb 6, 2022 at 21:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.