我想爲我的網站上的每個帖子/帖子製作一個表單。它從每個帖子後面發現郵件(每篇文章都有獨特的電子郵件),但我不會發送它。我的表單卡在某處。
<?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>
你知道你發送同樣的郵件2次,第二個是從if條件發送,並且當你使用wordpress時,你可以在'mail();' –
@ArshSingh的地方使用'wp_mail();'這就是我的最後一個問題。它不是首先發送。 –