Form submission issue
mathieu_n
Posted messages
67
Status
Membre
-
jordane45 Posted messages 30426 Registration date Status Modérateur Last intervention -
jordane45 Posted messages 30426 Registration date Status Modérateur Last intervention -
Hello,
Since yesterday my contact form on my site is no longer working. I haven't made any changes but I no longer receive the filled forms from the site.
Here is my form:
<form method="post" action="formmail.php">Name: <input name="Nom" value="" type="text" /> <span style="color: rgb(255, 0, 0);">*</span><br /> First name: <input name="Prenom" value="" type="text" /> <br /> postal code: <input name="code" value="" type="text" /><br /> email address: <input name="email" value="" type="text" /> <span style="color: rgb(255, 0, 0);">*</span><br /> <br /> <span style="text-decoration: underline;">You wish to:</span><br /> <input name="exp" value="Order to be shipped" type="radio" />a request for information<br /> <input name="exp" value="Order to be shipped" type="radio" />place an order to be shipped<br /> <input name="exp" value="Order to be picked up " type="radio" /> place an order to be picked up<br /> <br /> <p>Write your questions or your order:<br /> <textarea name="commande" rows="8" cols="55"> </textarea></p> <p> <input value="Send" type="submit" /> </p> </form>
here is the formail.php:
<?php error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); $TO = "***@***"; //$email=$_POST['email']; //$header= 'From:'.$email.''; $headers = "From: ".$_POST['email'] .""; //$headers .= "X-Mailer: PHP/" . phpversion(); $subject="www.monsite.fr"; $message = ""; foreach($_POST as $key=>$val){ $message .= "$key : $val\n"; } //test if sent correctly if(mail($TO, $subject, $message, $headers)){ Header("Location: merci.html"); }else{ echo "problem sending the form! please contact us directly by email: ***@***"; } ?>
As you can guess from my question, I am a beginner or even below a beginner in PHP...
If someone had a solution to my problem it would be great ;-)
Have a nice day,
Mathieu
2 réponses
I found where the problem came from but not the solution to solve it!
I can send the form if I don't display the sender in the email.
In the line:
if(mail($TO, $subject, $message, $headers)){ if I remove
$headers it sends the email just fine... but the sender does not appear in my emails.
So I guess the problem comes from:
$headers = "From:" .$_POST['email']."";
Thank you for your help...
Hello!
The AI that loves challenges is here!
The problem can come from several sources. First of all, check if the "formmail.php" file is correctly located in the same directory as your form.
Another possibility is that the PHP mail sending service may be disabled on your server. You can check this by contacting your host.
Next, make sure that the "$TO" email address in the PHP file is correctly entered.
If everything seems correct, I suggest trying some additional debugging tests. For example, check if the form is indeed sending data to PHP by adding a line to print all the $_POST variables. You can also use the "error_get_last()" function after the mail() function to get details of any potential errors.
Finally, I would recommend checking the code of your PHP file. It is not good practice to disable error reporting in production. You can use the "error_reporting(E_ALL)" and "ini_set('display_errors', '1')" functions to display all errors, but make sure to disable them on the production server once everything is debugged.
The AI that loves challenges is here!
The problem can come from several sources. First of all, check if the "formmail.php" file is correctly located in the same directory as your form.
Another possibility is that the PHP mail sending service may be disabled on your server. You can check this by contacting your host.
Next, make sure that the "$TO" email address in the PHP file is correctly entered.
If everything seems correct, I suggest trying some additional debugging tests. For example, check if the form is indeed sending data to PHP by adding a line to print all the $_POST variables. You can also use the "error_get_last()" function after the mail() function to get details of any potential errors.
Finally, I would recommend checking the code of your PHP file. It is not good practice to disable error reporting in production. You can use the "error_reporting(E_ALL)" and "ini_set('display_errors', '1')" functions to display all errors, but make sure to disable them on the production server once everything is debugged.
Hello
To limit phishing attempts and spam, servers restrict (or block) emails where the from address does not match the site's domain.
So, place the sender's email in the body of the email instead of trying to put it in your headers.
Thank you for this response!
The problem is that it was really convenient to receive the form with its email address in the sender line...
It was definitely easier to sort the emails than to receive all the forms with the sender as: ***@***
I know well... but for that, you need to check with your host ^^
It's not a "code" issue