mail () function question.

Discussion in 'PHP' started by kapadokis, Nov 2, 2009.

  1. #1
    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?
     
    kapadokis, Nov 2, 2009 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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
     
    JAY6390, Nov 2, 2009 IP
  3. kapadokis

    kapadokis Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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() ?>" />
     
    kapadokis, Nov 2, 2009 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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.
     
    JAY6390, Nov 2, 2009 IP
  5. Alecoalec

    Alecoalec Member

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5

    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?
     
    Alecoalec, Nov 2, 2009 IP
  6. kapadokis

    kapadokis Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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?
     
    kapadokis, Nov 2, 2009 IP
  7. jgalvez

    jgalvez Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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.
     
    jgalvez, Nov 2, 2009 IP
  8. nice.wallpapers

    nice.wallpapers Active Member

    Messages:
    142
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #8
    nice.wallpapers, Nov 3, 2009 IP