PHP不会工作,不会发送电子邮件

时间:2015-07-31 14:37:36

标签: php html email

我一直在尝试创建一个从网站发送电子邮件的PHP脚本,但每次我尝试发送它只是在空白页面上显示PHP代码, 这是我的HTML代码

<div class="contactcontent">
  <h2>Постави прашање: </h2>
  <form action="../pmp-dpatu/php/contact.php" method="post">
<strong>Име</strong><br>
<input type="text" name="cf_name"><br>
<strong>E-mail</strong><br>
<input type="text" name="cf_email"><br>
<strong>Текст</strong><br>
<textarea name="cf_message"></textarea><br>
<input type="submit" value="Send">
<input type="reset" value="Clear">
</form>
</div>

它可以工作并在浏览器中正确显示但是当我发送电子邮件时它只是进入PHP页面。 这是我的PHP代码

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'dpatu_mihajlo_pupin@yahoo.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;

$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 = 'contact.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to gordon@template-help.com');
        window.location = 'contact_page.html';
    </script>
<?php
}
?>

0 个答案:

没有答案