所以我试图为我的联系我们页面创建一个电子邮件表单。我的问题是我不知道如何这个电子邮件的形式我有这个代码为我的形式如下所示:
<form method = "post" action = "contactus.php" enctype="multipart/form-data">
<div class = "emailform">
<input type = "text" placeholder = "Name" name = "name" style="width:450px; padding:5px;" required><br>
<input type = "text" placeholder = "Email" name = "email" style="width:450px; padding:5px;" required><br>
<textarea name = "message" placeholder = "Message" style = "width:450px; padding: 5px; height: 155px;" required></textarea><br>
<button type = "submit" name = "send">Send</button>
</div>
</form>
如果有人回答会很有帮助顺便说一下,我只使用notepad++来编辑我的代码。而且我也是个新手:)
提前感谢
在您的contactus.php页面中试试。
<?php
$to = "recieveraddress@mail.com";
$subject = "Your subject";
$txt = $_POST['message'];
$headers = "From: ".$_POST['email'];
mail($to,$subject,$txt,$headers);
?>
在"contactus.php"文件中添加以下代码。并将"your@email.com"替换为您的电子邮件地址。请将"contactus.php"放在表单文件所在的目录下。
<?php
function clean($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if(isset($_POST['name'],$_POST['email'],$_POST['message']) && $_POST['name'] != '' && $_POST['email'] != '' && $_POST['message'] != '') {
foreach($_POST as $key = > $value)
$_POST[$key] = clean($value);
$to = 'your@email.com';
$from = $_POST['email'];
$subject = 'Customer support needed';
$message = 'Name='.$_POST['name'].' Message='.$_POST['message'];
// Sending email
if(mail($to, $subject, $message)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
}
?>