I am trying to make a form for every post/thread on my site. It finds the mail from behind every post (every post got an unique email) but i doesn't send it foward. My form is stuck somewhere.
<?php
global $wpdb;
global $post;
global $current_user;
global $wp_query;
$author_ID = get_query_var('post_author');
$to=the_author_meta('user_email',$author_ID);
//searching and showing up the email on the screen. working fine until here.
if(isset($_POST['submit'])){
$from = get_option( 'admin_email' ); //getting admin email
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = "Form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
// mail($to,$subject,$message,$headers);
if (mail($to,$subject,$message,$headers)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
//email is not send. "something went wrong" popping up.
}
?>
Every post/thread has a email behind, calling it, it shows up well. But the email is not send to the addres.
<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>
<form action="" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>