THe code below does not work. This is the code inside my contact page (page-kontakt.php) :
<h4>Send Us Mail</h4><br/>
<?php
if ($_GET[msg_sent]=='true' ) {
echo '<div>Your message has been sent!</div>';
}elseif ($_GET[msg_sent]=='false') {
echo '<div>An error occurred sending your message.</div>';
}else{
?>
<form method="post" action="<?php echo LEARNINGWORDPRESS_THEME_URL ?>functions.php">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<label>*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here">
<input id="submit" name="submit" type="submit" value="Submit">
</form>
<?php } ?>
This is the code inside my functions page (functions.php) :
// KONTAKT - MESSAGE SENDING FUNCTIONS FOR page-kontakt.php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: http://muzykablog.pl/';
$to = 'piterdeja@gmail.com';
$subject = 'Hello';
$human = $_POST['human'];
$body = "From: $name
E-Mail: $email
Message:
$message";
if(mail($to, $subject, $body, $from)){
header('Location:page-kontakt.php?msg_sent=true');
}else{
header('Location:page-kontakt.php?msg_sent=false');
}
In my wordpress site I want to be able to enter muzykablog.pl/kontakt where my contact form is (right now url muzykablog.pl/kontakt does not work) and after filling all the input windows like 'email' 'message' and clicking 'submit' I want to receive email message to the email address which I specified. Notice that I specified absolute path:
<form method="post" action="<?php echo LEARNINGWORDPRESS_THEME_URL ?>functions.php">
Maybe it is necessary to specify absolute path in
Location:page-kontakt.php?msg_sent=true
...as well, but how to specify absolute path in functions.php ?
You should change the code like this. Change the form action to blank
<form method="post" action="">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<label>*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here">
<input id="submit" name="contactSubmit" type="submit" value="Submit">
</form>
in functions.php you need to do the following code.
add_action('init','contact_submit');
function contact_submit(){
//contactSubmit is name of submit input field
if($_POST['contactSubmit']){
you submit code will be here
}
}
Since You are using wordpress why don't you use some premade solutions such as contact form 7. you could simply grab the plugin from repository and use shortcodes to insert in your page. you Could even style it if you require