I'm trying to create a form that will send to my email. The form works perfectly in Firefox, however, it does not work in Chrome/Internet Explorer . Hopefully someone can help!
EDIT What's happening is that my php is simply being displayed as text in the browser EDIT
HTML CODE:
<form action="contact.php" method="post" id="contactform">
<label for="myName">Name: </label>
<input type="text" name="myName" id="myName" />
<label for="myEmail">E-mail: </label>
<input type="email" name="myEmail" id="myEmail" />
<label for="myNumber">Phone Number: </label>
<input type="tel" name="myNumber" id="myNumber" />
<label for="myComments">Comments: </label>
<textarea name="myComments" id="myComments" rows="2" cols="20"></textarea>
<input id="mySubmit" type="submit" value="Submit">
</form>
PHP:
<?php
$field_name = $_POST['myName'];
$field_email = $_POST['myEmail'];
$field_phone = $_POST['myNumber'];
$field_message = $_POST['myComments'];
$mail_to = 'alexandriadrugs@yahoo.com';
$subject = 'Message from '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Phone: '.$field_phone."\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 alexandriadrugs@yahoo.com');
window.location = 'contact.html';
</script>
<?php
}
?>`
Firefox will run Php from the file directory while IE and Chrome will display them as plain text unless you specically tell them to run the file as the HTTP protocol. This may seem like a bug but they are infact doing a better job than Firfox by following the correct protocols being asked for:
OPEN FILE: file:///C:/xampp/htdocs/mypage.php
Request Webpage http:// localhost/mypage.php
I'm pretty sure that you're not running a web server that supports PHP. The PHP code won't be recognised that way, and it will be displayed like it's html.
http://
localhostYou should have your problem solved
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.