Hello I ve made a page (http://villa-portoheli.com/contact_el.php It s work is to send an email when someone press the submit button, but unfortunately send a blank email when I load the page too. Can anybody help me about this bug?
post the PHP code. More than likely you are not checking if the form has been submitted around the mail function so it sends regardless
this is the php: function mailto() { $subject = $_GET["his_name"]; $telephone = $_GET["tel"]; $from = $_GET["e_mail"]; $body = wordwrap ($_GET["notes"],70); $enimerwsi = $_GET["enimerwsi1"]; $enimerwsi2 = $_GET["enimerwsi2"]; if (mail('thanax99@yahoo.com', $subject, $body, $from, $tel)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed... </p>"); } } and the button is this: <input style="font-size:10px" name="button" type="submit" value="Υποβολή ΕνδιαφÎÏοντος" onClick="<?php mailto() ?>" />
PHP is a server side language, it gets processed BEFORE the page is displayed on the screen. You need to create a proper form and check the form input in the php script, and send if the forms been submitted.
I recommend you following a tutorial because there are several things that look incorrect here. Do you have a form, or just a "Submit" button?
yes I have a form but I thought to be useless to write it... Yes I am really newbie to all this, but I have to create it although!! the funtion works fine. The problem is that it works also every time the page is loaded sending a blank email. Do I need to put the function of the mail to the head section of the file?
Yes, basically rather then trying to trigger the mailto() when someone clicks the button (which is client side) you need to use PHP to check if the button and related information has actually been submitted, if it has been THEN you would trigger the mailto() function. What you are doing is confusing server side and client side events. Look up a few tutorials on PHP forms, it seems that is where your knowledge is lacking. Don't worry though, it's easy to learn and you'll get the hang of it soon.
Hi, You can learn mail function from here : http://in2.php.net/manual/en/book.mail.php It is very easy. Thanks,