Reputation: 376
I am trying to submit a html form to a php file, which sends a mail. I tryied before woth ajax and it behaved very strange, when i changed to pure html & php it also behaved strange. So i have this form:
<form id="comandaform" action="send.php" method="post">
<div class="ordercol">
<label for="nume">Nume companie</label>
<input type="text" id="nume" name="nume" />
<label for="email">Email</label>
<input type="text" id="email" name="email" />
<label for="tel">Telefon (te sunam noi!)</label>
<input type="text" id="tel" name="tel" />
</div>
<div class="ordercol">
<label for="detalii">Detalii despre domeniul tau de activitate</label>
<textarea name="detalii" id="detalii"></textarea>
<input type="submit" id="submit" value="trimite"/>
</div>
</form>
The PHP script that handles this is:
<?php
$nume = $_POST["nume"];
$mail = $_POST["email"];
$tel = $_POST["tel"];
$det = $_POST["detalii"];
$mess = "";
if(isset($nume)&&isset($mail)&&isset($tel)&&isset($det))
{
$to = '[email protected]';
$subject = 'Comanda Site100';
$message = 'Nume companie: '.$nume.'\n'.
'Telefon: '. $tel.'\n'.
'E-mail: '. $mail.'\n'.
'Detalii:\n'.
$det;
if(mail($to, $subject, $message))
{
echo "succes";
}else{
echo "fail";
}
}else{
echo "fail";
}
?>
When i try to submit, the browser will not find the send.php
file. Am i doing something wrong?
Upvotes: 0
Views: 2409
Reputation: 971
Two things I noticed about your code right away.
First, if your browser is not finding send.php
, that strongly indicates that you have a pathing error. You're either missing a subfolder in your HTML action pathing, or the file is located somplace other than where you expect it to be.
Second, even if you do find the form, it will likely kick out an error. If any of those fields are blank, you will get an error unidentified index call
when trying to assign the $_POST key to a local variable. Next, when you check to see if the variable is set, well, of course they are, after all, you just set them. They will have a value of undefined, however, if any of the fields of the form are left blank.
//Use an inline check when assigning the form field values
$nume = isset($_POST["nume"]) ? $_POST["nume"] : '';
Then, when it comes to checking for completeness...
//Check for empty values
if (!empty($nume) && !empty($mail) && !empty($tel) && !empty($det)){
// Etc...
Upvotes: 0
Reputation: 1670
Do you actually get a file not found error?
add a line write at the top of your send.php
something like:
echo 'processing form...';
just so you can see that the page is loading properly.
then try just loading it manually
eg.
if you form is at
http://www.mydomain.com/form.html
then try loading send.php by typing
http://www.mydomain.com/send.php
make sure it loads ok.
you could also change all the $_POST to $_REQUEST then you can test it with a query string
eg.
http://www.mydomain.com/send.php?nume=bob
that should move you in the right direction towards finding your problem... if not post back letting us know what happened with the above.
Upvotes: 1