我是网页设计的新手。我从html开始,用ext .html创建一些页面 但是现在我想在我的html页面中添加一个联系我们表单或者在我们的表单中添加消息。那我怎么能这样做呢。其实我想使用html页面,那个html页面可以执行php脚本。
提前致谢。
答案 0 :(得分:3)
试试这个..您可以使用PhpMailer或您喜欢的任何其他邮件程序将邮件发送到其他服务器。此代码仅适用于您的服务器。
<form action="" method="POST" enctype="multipart/form-data">
<fieldset>
<label><span class="text-red">*</span> Full name:</label>
<input type="text" id="contact-name" name="mname" required/>
</fieldset>
<fieldset>
<label><span class="text-red">*</span> Email:</label>
<input type="email" name="email" id="contact-email" required/>
</fieldset>
<fieldset>
<label>Link to your portfolio or personal website (Optional)</label>
<input type="text" id="portfolio-link" name="mlink"/>
</fieldset>
<fieldset>
<label><span class="text-red">*</span> Message:</label>
<textarea rows="5" id="contact-message" name="mmsg" required></textarea>
</fieldset>
<input type="submit" value="Submit" name="submitmail" />
</form>
<?php
if (isset($_POST['submitmail']))
{
$name=$_POST['mname'];
$email = $_POST['email'];
$link= $_POST['mlink'];
$message = $_POST ['mmsg'];
$headers .= "From: Display title ";
$message = 'Name: '.$name."\r\n".'Email: '.$email."\r\n". 'Portfolio / Website Link: '.$link."\r\n". 'Message: '.$message ;
$mail= mail("abc@yourdomain.com" , "Feedback/Query" , $message , $headers);
if ($mail == true) {
echo "<script>alert('Thank you. We will contact you soon..!!');</script>";
}
else
{
echo "<script>alert('Something is not right. Please try again.');</script>";
}
}
?>
答案 1 :(得分:1)
创建像contact.html这样的html页面并放在代码下面
<form action="email.php" method="POST" enctype="multipart/form-data">
<fieldset>
<label><span class="text-red">*</span> Full name:</label>
<input type="text" id="contact-name" name="mname" required/>
</fieldset>
<fieldset>
<label><span class="text-red">*</span> Email:</label>
<input type="email" name="email" id="contact-email" required/>
</fieldset>
<fieldset>
<label>Link to your portfolio or personal website (Optional)</label>
<input type="text" id="portfolio-link" name="mlink"/>
</fieldset>
<fieldset>
<label><span class="text-red">*</span> Message:</label>
<textarea rows="5" id="contact-message" name="mmsg" required></textarea>
</fieldset>
<input type="submit" value="Submit" name="submitmail" />
</form>
现在创建类似email.php的内容并放在代码
下面<?php
if (isset($_POST['submitmail']))
{
$name=$_POST['mname'];
$email = $_POST['email'];
$link= $_POST['mlink'];
$message = $_POST ['mmsg'];
$headers .= "From: Display title ";
$message = 'Name: '.$name."\r\n".'Email: '.$email."\r\n". 'Portfolio / Website Link: '.$link."\r\n". 'Message: '.$message ;
$mail= mail("abc@yourdomain.com" , "Feedback/Query" , $message , $headers);
if ($mail == true) {
echo "<script>alert('Thank you. We will contact you soon..!!');</script>";
}
else
{
echo "<script>alert('Something is not right. Please try again.');</script>";
}
}
?>
记住,邮件功能只有在你的localhost有设置时才有效,否则你需要像phpmailer或者其他东西一样使用smtp ..总有一种最佳做法是使用phpmailer而不是php的邮件功能。