基本上我有一个页面,只有在用户登录时才会向他们显示,它上面有一个自定义联系表单。提交表单后,他们的用户角色应自动更改为“作者”。
我真的不知道从哪里开始,如果有人有任何想法或可以帮助我一点,那将是惊人的,因为我真的在努力解决这个问题。
编辑
这就是我目前所拥有的,它现在所做的就是发送电子邮件。
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = trim(stripslashes($_POST['name']));
$email = trim(stripslashes($_POST['email']));
$subject = trim(stripslashes($_POST['subject']));
$message = trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'email@email.com';
$body = '<html><head></head><body>' .
'<b>Name:</b> ' . $name . '<br><br>' .
'<b>Email:</b> ' . $email . '<br><br>' .
'<b>Nature of Enquiry:</b> ' . $subject . '<br><br>' .
'<b>Message:</b> ' . nl2br($message) .
'</body></html>';
$headers = "From: " . strip_tags($email_from) . "\r\n";
$headers .= "Reply-To: ". strip_tags($email_from) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if( isset($_POST['checkbox']) ) {
mail($email_to, $subject, $body, $headers);
// Change user role to "author
echo '<p>You are now an author.</p>';
} else {
echo '<p>It appears you are a spambot, if this is a mistake please try again and check the "I am not a spambot" checkbox.</p>';
}
}
?>
<form method="post" action="#">
<label for="name">Name</label>
<input type="text" id="name" name="name" value="<?php echo $name; ?>" required>
<label for="email">Email Address</label>
<input type="email" id="email" name="email" value="<?php echo $email; ?>" required>
<label for="subject">Nature of Enquiry</label>
<input type="text" id="subject" name="subject" value="<?php echo $subject; ?>" required>
<label for="checkbox">I am not a spambot</label>
<input type="checkbox" id="checkbox" name="checkbox">
<label for="message">Message</label>
<textarea id="message" name="message" required><?php echo $message; ?></textarea>
<button type="submit">Submit</button>
</form>