How to send e-mail from form in wordpress - wordpress

I am new in programing and WordPress. I want to send a e-mail from my form with a message, phone, ect. Can anyone tell me how can i do that?
Here is my code so far...
<div id="form">
<?php
add_filter('wp_mail_content_type','set_content_type');
function set_content_type($content_type){
return 'text/html';
}
?>
<div id="name">
<p id="username"> Name: </p>
<input type="text" name="name" class="textfield">
</div>
<div id="name">
<p id="username"> Email: </p>
<input type="text" name="name" class="textfield">
</div>
<div id="name">
<p id="username"> Phone: </p>
<input type="text" name="name" class="textfield">
</div>
<div id="name">
<p id="username"> Message: </p>
<input type="text" name="message" class="textarea">
</div>
<input type="button" value="SEND" id="btn">
</div>

To send mail from a form with following fields, open a new file and copy these lines and save (e.g. mail.php):
<?php
//sending mail
if(isset($_POST['sub']))
{
$uname=$_POST['uname'];
$mailid=$_POST['mailid'];
$phone=$_POST['phone'];
$message=$_POST['message'];
if(mail($uname,$mailid,$phone,$message))
{
echo "mail sent";
}
else
{
echo "mail failed";
}
}
?>
<form name="frm" method="post" action="#">
<label for="uname">Name:</label>
<input type="text" value="" name="uname" id="uname"><br/>
<label for="mailid">Email:</label>
<input type="text" value="" name="mailid" id="mailid"><br/>
<label for="mobile">Phone:</label>
<input type="text" value="" name="phone" id="phone"><br/>
<label for="message">Message:</label>
<input type="text" value="" name="message" id="message"><br/>
<input type="submit" value="Submit" name="sub" id="sub">
</form>

It will have to be much more complicated than what you have at the moment.
My first recommendation would be to use some, rather top-heavy, form plugins, But you will save yourself a lot of time and trouble like that.
http://www.deliciousdays.com/cforms-plugin/
http://wordpress.org/extend/plugins/contact-form-7
My 2nd recommendation would be to follow a popular tutorial for a full custom form to email script.
http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme
Note: Beware of spam bots and various other possible dangers of just putting a public form up on the web. If's very possible that you will have a hole in your custom code and a could cause some damage if exploited by the right person.

Related

Obtain data from a form in wordpress

I'm building a wordpress website using Avada tamplate. I use the Avada login form in which the users insert their username and password. I would like to get the username of the user when he click on the form button and he's redirect to login.php page. I don't understand why I can't do that.
The code of the form (i removed "class" and "style" in order to reduce it) is:
<form name="loginform" id="loginform" method="post" action="http://www.mywebsite.com/es/wp-login.php">
<div>
<div>
<label for="user_login">Username</label>
<input type="text" name="log" placeholder="Username" value="" size="20" id="user_login" />
</div>
<div>
<label for="user_pass">Password</label>
<input type="password" name="pwd" placeholder="Password" value="" id="user_pass" />
</div>
</div>
<div>
<div>
<button type="submit" name="wp-submit">Log in</button>
<input type="hidden" name="user-cookie" value="1" />
<input type="hidden" name="redirect_to" value="login.php" />
<input type="hidden" name="fusion_login_box" value="true" />
<input type="hidden" name="_wp_http_referer" value="/es/area-privada/" /><span></span></div>
<div></div>
</div>
</form>
The login.php code is very simple:
<?php
$username = $_POST['log'];
echo $username;
?>
however the variable $username is blank and doesn't capture the username. Someone can help me please? thanks!

Wordpress form link broken

I have a pre-form on a Wordpress site (localhost) where users submit their name, email, etc., before continuing to the first part of a multi-page quiz.
The problem is, if I enter any details, Wordpress directs to a 404 page. But if I leave them blank (obviously I want to make these required fields) then it directs to the next page all ok.
I have checked my .htaccess file, Apache settings and followed all the other possible solutions I have found on SO and elsewhere, but nothing I have found fixes the issue.
Here's my code:
<div class="pre-quiz">
<form action="<?php bloginfo('url'); ?>/part-1" method="post">
<div class="form-group row">
<div class="col-xs-6">
<input type="text" class="form-control" name="name" id="name" placeholder="First name">
</div>
<div class="col-xs-6">
<input type="text" class="form-control" name="surname" id="surname" placeholder="Last name">
</div>
</div>
<div class="form-group">
<input type="text" class="form-control" name="business" id="business" placeholder="Business name">
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" id="email" placeholder="Email address">
</div>
<div class="custom-control custom-checkbox custom-control px-4 pb-4 pt-2">
<input type="checkbox" class="custom-control-input" name="terms" id="terms" value="terms">
<label class="custom-control-label" for="terms">
I accept the Terms of Use & Privacy Policy
</label>
</div>
<div class="form-group">
<button type="submit" class="btn btn-block">Next step</button>
</div>
</form>
</div>
Any help would be appreciated.
Thanks
I don`t see any error. Try to name your checkbox not "terms", maybe there is a conflict.
Regards Tom
Tom, I took your idea and tried it with all the other fields to see if Wordpress was using 'name' or 'email' and changed them to something unique - It worked! Thanks again for your input.

Login from WordPress to External Site

I'm trying to do a generalized script for any WordPress theme which will display a 'Login' or 'Sign-In' link, then show login username, pwds fields, and upon Submit POST to another site with the login info and log them in.
I've done some CSS and code in some themes' header.php file like this:
<div class="sign-in-wrapper">
<div class="sign-in-dropdown">
<form name="login" id="sign-in-form"
<?php if($_SERVER['SERVER_NAME'] == "www.mysite.com") { ?>
action="https://secure.mysite.com/"
<?php } ?>
method="POST">
<input type="hidden" name="thisaction" id="thisaction" value="">
<b>User Name:</b>
<input type="Text" name="UserName" size="41" class="forminput1" value="">
<b>Password:</b>
<input type="password" name="pwd" size="41" class="forminput1">
<input type="submit" value="Sign In" name="login" border="0">
</form>
</div>
</div>
<div id="sign-in-link"><a class="sign-in" url="#top">Sign in</a> </div>
It works in some themes but not in others.
Is there a good way to do this?

Functioning of Wordpress Contact form to Laravel Method

On my website there is a contact form on footer which is working fine.
Site Blog is on wordpress have same contact form.
I don't wan't to create working again for wordpress contact form
<form action="/yocreativ/contact-us" method="post">
<?php
//Generate a random string.
$token = openssl_random_pseudo_bytes(20);
//Convert the binary data into hexadecimal representation.
$token = bin2hex($token);
//Print it out for example purposes.
// echo $token;
?>
<input type="hidden" name="_token" value="<?php echo $token; ?>">
<div class="form-group col-lg-4 wow fadeInDown animated" data-wow-delay="0.2s">
<input type="text" name="name" class="form-control" id="name" placeholder="NAME" required="required">
</div>
<div class="form-group col-lg-4 wow fadeInDown animated" data-wow-delay="0.2s">
<input type="email" name="email" class="form-control" id="email" placeholder="EMAIL" required="required">
</div>
<div class="form-group col-lg-4 wow fadeInDown animated" data-wow-delay="0.2s">
<input type="tel" name="phone" class="form-control" id="subject" placeholder="PHONE" pattern="^\d{3}\d{3}\d{4}$" required="required">
</div>
<div class="form-group col-lg-12 wow fadeInDown animated" data-wow-delay="0.2s">
<textarea name="message" id="message" cols="30" rows="5" placeholder="MESSAGE" required="required"></textarea>
</div>
<div class="row">
<div class="col-lg-12">
<button type="submit" class="btn contact-submit">SEND</button>
</div>
</div>
</form>
Form action="/yocreativ/contact-us" which is the route of my laravel app.
When i submit the form it says.
The page has expired due to inactivity.
Please refresh and try again.
For WordPress wp_nonce_field and wp_verify_nonce field to verify.
https://codex.wordpress.org/Function_Reference/wp_nonce_field
Form field like:
<form method="post">
<?php wp_nonce_field('name_of_my_action','name_of_nonce_field'); ?>
</form>
In action file
<?php
if ( empty($_POST) || !wp_verify_nonce($_POST['name_of_nonce_field'],'name_of_my_action') )
{
print 'Sorry, your nonce did not verify.';
exit;
}
else
{
// process form data
}

Zombie.js can't find button element on page

I'm trying to submit a form with zombie.js, and pressButton() is failing with "Error: No BUTTON 'xxx'", where xxx is the selector. Here is the app:
var Browser = require('zombie');
b = new Browser();
b.visit('https://www.example.com/login/', function() {
b.
fill('name', 'My Name').
fill('code', 'My Code').
pressButton('submit', function() {
console.log(b.html());
});
});
And here is the form:
<form method="post" class="login">
<p> <label for="name"> <span id="nameprompt">Your Name:</span> </label> </p>
<input name="name" id="name" value="" size="40" maxlength="40" />
<p> <label for="code"> <span id="codeprompt">Bar Code</span> </label> </p>
<input name="code" id="code" type="PASSWORD" value="" size="40" maxlength="40" />
<div class="formButtonArea">
<input type="image" src="/screens/pat_submit.gif" border="0" name="submit" value="submit" />
</div>
</form>
I've tried a bunch of selectors including things like ".formButtonArea input" in addition to the obvious "submit" with no success.
What am I doing wrong?
It seems like you need the input to be of type="submit" (or type="button" perhaps). According to https://groups.google.com/forum/?fromgroups=#!topic/zombie-js/8L0_Cpn8vVU, where the author comments on clickLink, it's likely that clickButton will do the same: find buttons and then fire click.
Hope it helps.

Resources