SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 34 of 34

Thread: php.in file

  1. #26
    SitePoint Member
    Join Date
    Aug 2010
    Location
    London
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    This is how my code looks like in send.php page, but it doesn't work. Any ideas why?

    <?php
    //start building the mail string
    $msg .= "Name: ".$_POST["name"]."\n";
    $msg .= "E-Mail: ".$_POST["emailaddress"]."\n";
    $msg .= "Tel No: ".$_POST["telNr"]."\n";
    $msg .= "Message: ".$_POST["limitedtextarea"]."\n";

    //set up the mail
    $recipient = "email@email.co.uk";
    $subject = "Subject";
    $mailheaders = "Mailheaders<email@email.com> \n";
    $mailheaders .= "Reply-To: ".$_POST["email"];
    //send the mail
    mail($recipient, $subject, $msg, $mailheaders);

    if ($mailsent === true){

    header("Location: /index.html");
    exit(); // important!
    }
    ?>

  2. #27
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    "Doesn't work" is not very descriptive.

    What does not work? What error messages are you getting? What debugging have you done to narrow down which part does not work?

    ps $msg should be initialized before you concatenate stuff to it, maybe you do this higher up and have not shown us? Else:
    PHP Code:
    $msg "Name: ".$_POST["name"]."\n";  // <-rm the dot and initialise the variable
    $msg .= "E-Mail: ".$_POST["emailaddress"]."\n";
    $msg .= "Tel No: ".$_POST["telNr"]."\n";
    $msg .= "Message: ".$_POST["limitedtextarea"]."\n"
    pps get used to wrapping PHP code samples with [php ] [/php] tags, makes it easier for anyone else to read.

  3. #28
    SitePoint Member
    Join Date
    Aug 2010
    Location
    London
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By 'it doesn't work' I meant that id does not redirect to another page once the form is submitted.

    I realised, that it might be a wrong code. My form is on .html page, I want it to be send in the background (if it validates) and then thankyou.html to be displayed.

    Sorry..

  4. #29
    SitePoint Member
    Join Date
    Aug 2010
    Location
    London
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "PHP is a powerful tool for making dynamic and interactive Web pages." As it says on W3C Schools

    I said right at beginning I am new to PHP, sorry..

  5. #30
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    mail($recipient$subject$msg$mailheaders);

    if (
    $mailsent === true){

    header("Location: /index.html");
    exit(); 
    // important!

    I cannot see where $mailsent is being set, so must assume you really want to do this:

    PHP Code:
    if (mail($recipient$subject$msg$mailheaders) === true){

    header("Location: /index.html");
    exit(); 
    // important!

    Because if you read the manual very carefully on the mail() page in the first highlighted box it states:

    bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
    I draw your attention to "bool" that means mail will return either true or false, it won't return a string or nice message, just true or false.

    So that is something you can fork your code on with a conditional check,
    if (true)
    do this
    else
    do that

  6. #31
    SitePoint Member
    Join Date
    Aug 2010
    Location
    London
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, I'll try this code now. thanks a lot

  7. #32
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I'd feel a whole lot better if you said you understand the principle of the idea I just placed before you - or asked me questions if you did not understand what the heck bool or boolean meant.

    I'm not here to write code for you.

  8. #33
    SitePoint Member
    Join Date
    Aug 2010
    Location
    London
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know what boolean is, I've done some JavaScript. Boolean can be only true or false. They are can not be strings or arrays.

    I believe I need another part of code you wrote, the one to do something in IF mail is not true, if it does not validate.

    I'm not quite sure what header("Location: /index.html"); means. The second part says where it should be redirected, but I have to check 'header'.

  9. #34
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Entering "PHP header" into google will fetch up header - a PHP function which is similar to the JS location.href=xxxxxx


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •