Php邮件表单不起作用。参数$ to卡在一个循环中

时间:2017-03-26 16:59:03

标签: php email

我正在尝试为我网站上的每个帖子/帖子制作一个表单。它从每个帖子后面找到邮件(每个帖子都有一个独特的电子邮件),但我不发送它。我的表格被困在某个地方。

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

}

?>

每个帖子/帖子后面都有一封电子邮件,调用它,它显示得很好。 但是电子邮件不会发送到地址。

<!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> 

0 个答案:

没有答案