0

I have been trying to make a PHP script that sends email from a website but every time i try to send it just displays the PHP code on a blank page, here is my HTML code

<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>

it works and is displayed properly in the browser but when i send an email it just goes to the PHP page. here is my PHP code

<?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
}
?>
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • If it is displaying PHP code on a blank page you do not have PHP running on your webserver. – Jay Blanchard Jul 31 '15 at 14:41
  • PHP is installed, it just wont work, i have tried removing some of the \r and \n, nothing happens – Marko Psiho Jul 31 '15 at 17:58
  • Removing that is not going to make your PHP run. How are you accessing your pages? – Jay Blanchard Jul 31 '15 at 18:01
  • I have set up a testing server trough Dreamweaver on a different PC, PHP is running on both the PC i am using and the server. when I open the website trough my browser(Chrome) the HTML part works as expected, I fill the contact form, press send and the browser opens a page where only the PHP code is displayed. also i havent mentioned before, the HTML and The PHP are on different files, one is contact-mk.html ant the other contact.php and are linked with this line of code:
    – Marko Psiho Jul 31 '15 at 18:09
  • If the PHP code is displayed your webserver is not configured to run PHP. – Jay Blanchard Jul 31 '15 at 18:10

0 Answers0