我正在使用网站模板在我自己的家庭服务器上建立一个网站。联系表格使用 php 和 php mail() 函数通过电子邮件发送到联系表中输入的信息,但我没有本地 smtp 服务器可在 mail() 中使用。因此,我想更改代码以将提交的信息保存到文本文件中。如果有可能的方法可以做到这一点,有人可以指出我正确的方向。我目前的html代码和php代码如下: HTML:
<form action="mailer.php" id="contact_form" method="post">
<ul class="form">
<li class="short">
<label>First Name<span class="required"></span></label>
<input type="text" name="first" id="first" value="First Name" class="requiredField" onblur="if(this.value == '') { this.value = 'First Name'; }" onfocus="if(this.value == 'First Name') { this.value = ''; }" />
</li>
<li class="short">
<label>Last Name<span class="required"></span></label>
<input type="text" name="last" id="last" value="Last Name" class="requiredField" onblur="if(this.value == '') { this.value = 'Last Name'; }" onfocus="if(this.value == 'Last Name') { this.value = ''; }" />
</li>
<li class="long">
<label>Email Address<span class="required"></span></label>
<input type="text" name="email" id="email" value="Email Address" class="requiredField email" onblur="if(this.value == '') { this.value = 'Email Address'; }" onfocus="if(this.value == 'Email Address') { this.value = ''; }" /> </li>
<li class="short">
<label>Company Name</label>
<input type="text" name="company" id="company" value="Company Name" class="requiredField" onblur="if(this.value == '') { this.value = 'Company Name'; }" onfocus="if(this.value == 'Company Name') { this.value = ''; }" />
</li>
<li class="short">
<label>Telephone Number</label>
<input type="text" name="phone" id="phone" value="Telephone Number" class="requiredField" onblur="if(this.value == '') { this.value = 'Telephone Number'; }" onfocus="if(this.value == 'Telephone Number') { this.value = ''; }" />
</li>
<li class="textarea">
<label>Message<span class="required"></span></label>
<textarea name="message" id="message" rows="20" cols="30"></textarea>
</li>
<li class="button"><input name="submitted" id="submitted" value="Submit" class="submit" type="submit" />
</li>
PHP:
<?php
$email_to = "michaelggerhart@gmail.com";
$first = $_POST["first"];
$last = $_POST["last"];
$email = $_POST["email"];
$company = $_POST["company"];
$phone = $_POST["phone"];
$message = $_POST["message"];
$text = "NAME: $first $last <br>
EMAIL: $email<br>
COMPANY: $company<br>
TELEPHONE NUMBER: $phone<br>
MESSAGE: $message";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=utf-8" . "\r\n";
$headers .= "From: <$email>" . "\r\n";
mail($email_to, "Message", $text, $headers);
?>