我有一个带有联系部分的模板应该从页面发送电子邮件。我使用的是Cloud 9 ide 我的代码如下,这是html代码:
<div class="w-form">
<form action="contact.php" method="post">
<label for="name">Name:</label>
<input class="w-input" type="text" placeholder="Enter your name" name="cf_name">
<label for="email">Email Address:</label>
<input class="w-input" placeholder="Enter your email address" type="text" name="cf_email" required="required">
<label for="email">Your Message:</label>
<textarea class="w-input message" placeholder="Enter your Message Here" name="cf_message"></textarea>
<br>
<input class="w-button" type="submit" value="Send">
</form>
<div class="w-form-done">
<p>Thank you! Your submission has been received!</p>
</div>
<div class="w-form-fail">
<p>Oops! Something went wrong while submitting the form :(</p>
</div>
</div>
这是形式的动作值中引用的php代码,名为&#34; contact.php&#34;
<html>
<body>
<a href="index.html#contact">Click to return to the home page.</a>
</body>
</html>
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'arendtjda@gmail.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name.'\n';
$body_message .= 'E-mail: '.$field_email.'\n';
$body_message .= 'Message: '.$field_message.'\n';
$body_message .= 'CHANGE EMAIL TO';
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html#contact';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to arendtjda@gmail.com');
window.location = 'index.html#contact';
</script>
<?php
}
echo('')
?>
结果一无所获。我知道电子邮件的正文正在形成,因为我更改了PHP表单中的java脚本,它提醒用户发送电子邮件以包含正文。那么为什么这不起作用呢?我是初学者,我不知道如何更改服务器端设置。如果需要,请提供有关如何更改服务器设置的详细说明。
感谢您的帮助。