我正在尝试从网页发送电子邮件,但是当我单击提交按钮时,php 代码正在打开。我已经安装了 apache 服务器并启动并运行。我不太确定我缺少什么以及如何从网页发送电子邮件。我是否还需要安装 sendmail 和 php 以使其使用 apache 服务器在本地工作。下面是我的代码。请帮忙
<form action= "temp.php" method="post" name="sentMessage" id="contact" >
<div class="row">
<div class="col-md-6" style="margin-left:-5px;">
<div class="input-field">
<input type="text" name="name" class="form-control" id="name"
required
data-validation-required-message="Please enter your name" />
<label for="name" class=""> Name </label>
<p class="help-block"></p>
</div>
</div>
</div>
<!-- For success/fail messages -->
<button name="submit" type="submit"
class="btn btn-primary waves-effect waves-dark pull-right">Send</button>
<br />
</form>
和php代码如下。
<?php
if(isset($_POST['submit'])){
$to = "xyz@gmail.com"; // this is your Email address
$from = "abc@gmail.com"; // this is the sender's Email address
$subject = "Form submission";
$message = "form submission";
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
echo "Mail Sent";
}
?>