Wordpress return me 0, what am I doing wrong?
Opened this issue · 0 comments
Wolclaws commented
As mentioned in the title, Wordpress return me 0.
I require WP_Ajax and WP_Mail.
This is my code
`
Class Example extends WP_AJAX
{
protected $action = 'example';
protected function run(){
if (filter_var($this->get('email'), FILTER_VALIDATE_EMAIL)) {
$mymail = get_option( 'simplebooks_news_contact_mail',get_userdata(1)->user_email);
$email = WP_Mail::init()
->headers([
"From: ".$this->get('email'),
"Content-type: text/html; charset=iso-8859-1",
"MIME-Version: 1.0\n",
"X-Mailer: PHP " . phpversion()
])
->from($this->get('email'))
->to([$mymail,$this->get('email')])
->subject(__('New contact from enquiry','simplebooks').': {{name}}')
->template(get_template_directory() .'/emails/basic.html', [
'time' => date('Y-m-d H:i:s'),
'name' => $this->get('name').' '.$this->get('surname'),
'email' => $this->get('email'),
'message' => $this->get('message'),
])
->send();
}
}
}
`
and this the form
echo'<h2 class="ui header">'.get_option( 'simplebooks_news_contact_text',__('Contact me! Send me a mail!','simplebooks')).'</h2>
<form class="emailform" action="'.Example::url().'">
<div class="ui form text container mail-form">
<div>
<textarea id="message" class="mail-text" name="message" placeholder="'.__('Write me a message...','simplebooks').'"></textarea>
<div class="ui fields mail-input mail-hidden">
<div class="ui left icon input field mail-input mail-hidden">
<input class="mail-hidden" type="text" name="name" placeholder="'.__('Name','simplebooks').'">
<i class="user icon"></i>
</div>
<div class="ui field mail-hidden">
<input class="mail-hidden" type="text" name="surname" placeholder="'.__('Surname','simplebooks').'">
</div>
</div>
<div class="ui left icon input mail-input mail-hidden">
<input id="email" class="mail-hidden" type="email" name="email" placeholder="'.__('Your email','simplebooks').'">
<i class="envelope outline icon"></i>
</div>
</div>
<div>
<input id="website" class="no_spam" type="text" name="website">
<button class="ui icon button mail-submit disabled"><i class="envelope outline icon"></i><span class="mail-hidden">'.__(' Send','simplebooks').'</span></button>
</div>
</div>
</form>
';
What am I doing wrong?