I know what I am posting seems like a lot to go through, but I think it is all relevant to my problem.
Strange behavior when running php script combined with <html> form.
When I run this script it appears in the browser properly.
The file I am running is:
C:\xampp\htdocs\tutorials\contact_form\cont_w_email.php
Code:
<?php
if (isset($POST['contact_name']) && isset($POST['contact_email']) && isset ($POST['contact_text'])) {
$client_name = $POST['client_name'];
$client_email = $POST['client_email'];
$client_text = $POST['client_text'];
if (!empty($client_name) && !empty($client_email) && !empty($client_text)) {
$to = 'kentest894@gmail.com';
$subject = 'Contact form submitted.';
$body = $client_name."\n".$client_text;
$headers = 'From: '.$client_email;
if (mail($to, $subject, $body, $headers)) {
echo 'Thank you for contacting us. We will reply soon.'; //success message
} else {
echo '<strong><font color= "red">An error has occured !</font></strong>Please try again'; // error message
}
}
}
?>
<form action = "a_contact_form.php" method = "POST">
Name:<br><input type = "text" name = "contact_name"><br><br>
Email address:<br><input type = "text" name = "contact_email"><br><br>
Message:<br>
<textarea name = "contact_text" rows = "6" cols = "30"></textarea><br><br>
<input type = "submit" value = "send Mail">
</form>
After I put entries in the fields and click the send button the page redirects to: http://localhost/tutorials/contact_form/a_contact_form.php and shows "OK." in green font.
The file: tutorials/contact_form/a_contact_form.php
was once in the same folder
C:xampp\htdocs\tutorials\contact_form
but, I moved it to recycle bin to try to correct the redirect.
I will include code for thta file at the bottom of this post.
I again ran file: tutorials/contact_form/cont_w_email.php
It appeared as expected in the browser.
When I put entries into the fields and clicked submit button, I got the following result:
Object not found! Error 404.
I believe that the xampp php.ini & sendmail.ini are properly configured because I can run a simple php mial() script with out errors and show mail in
xampp mailoutput folder.
Code:
C:\xampp\htdocs\tutorials\email\email.php
Code:
<?php
$to = 'kentest894@gmail.com';
$subject = 'this is an email';
$body = 'This is a test email'."\n\n".'Hope you recieved it.';
$headers = 'From: someone@phpKen.org';
if (mail($to, $subject, $body, $headers)) {
echo 'Email has been sent to:'."<br>".$to;
} else {
echo 'There was a problem sending the email';
}
?>
I really can't figure out this redirect.
Please help.
Note: neither C:\xampp\tutorials\contact_form\a_contact_form.php
C:\xampp\tutorials\contact_form\cont_w_email.php
produce mail to the mailoutput folder.
Code: for a_contact_form.php
<?php
if (isset($POST['contact_name']) && isset($POST['contact_email']) && isset ($POST['contact_text'])) {
$contact_name = $POST['contact_name'];
$contact_email = $POST['contact_email'];
$contact_text = $POST['contact_text'];
if (!empty($contact_name) && !empty($contact_email) && !empty($contact_text)) {
echo '<strong><font color= "green">OK.</font></strong>';
} else {
echo '<strong><font color= "red">All fields required !</font></strong>';
}
}
?>
<form action = "a_contact_form.php" method = "POST">
Name:<br><input type = "text" name = "contact_name"><br><br>
Email address:<br><input type = "text" name = "contact_email"><br><br>
Message:<br>
<textarea name = "contact_text" rows = "6" cols = "30"></textarea><br><br>
<input type = "submit" value = "send">
</form>