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.
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?