这个问题在这里已有答案:
我是第一次使用html进行Web开发。我有一个网站,我想要一个信息提交表格,必须发送电子邮件而不打开outlook。我试着用http POST请求并使用PHP处理它。
问题是它不发送电子邮件。我不知道为什么。
我的SendEmail.php文件是:
<?php
if(isset($_POST['submit']))
{
$to = "[email protected]"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['name'];
$subject = "Form submission";
$message = $first_name . " " . " wrote the following:" . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
我的HTML是:
<div class="contact">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h4>Please Contact With Us For Any Kind Of Information></h4>
<form id="contactform" action="SendEmail.php" method="post" class="validateform" name="send-contact">
<div class="row">
<div class="col-lg-4 field">
<input type="text" name="name" placeholder="* Your Name" data-rule="maxlen:4" data-msg="Please enter at least 4 chars" />
</div>
<div class="col-lg-4 field">
<input type="text" name="email" placeholder="* Your Email" data-rule="email" data-msg="Please enter a valid email" />
</div>
<div class="col-lg-4 field">
<input type="text" name="subject" placeholder="Subject" data-rule="maxlen:4" data-msg="Please enter at least 4 chars" />
</div>
<div class="col-lg-4 field">
<input type="text" name="ContactNumber" placeholder="* Contact Number" data-rule="required" data-msg="Please enter your number" />
</div>
<div class="col-lg-12 margintop10 field">
<textarea rows="12" name="message" class="input-block-level" placeholder="* Your message here..." data-rule="required" data-msg="Please write something"></textarea>
<p>
<button name="submit" value="submit" class="btn btn-theme margintop10 pull-left" type="submit">Submit message</button>
</p>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
有人可以帮我发送电子邮件吗?
在HTML中,将表单操作更改为SendEmail.php
而不是绝对路径。
如果您在使用php的网络服务器上运行您的代码,它现在应该可以使用。