SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict Johana Solendhal's Avatar
    Join Date
    Aug 2004
    Location
    Land of the free
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't get this to work! Redirection and mail function

    Hola guys!!

    Why oh why can't I get this to work?

    The idea is this: This file is processed via an action in a form. The information is added to the database, then the mail functions sends the mails with the configurations from the order-process-config.php file, and then the user get's redirected via header method.

    The mail funcion and the redirection isn't working!

    PHP Code:

    <?php
    include_once("../admin/admin/config.php");
    require(
    "scripts/order-process-config.php");
    // Check user logged in already:
    checkLoggedIn("yes");
    doCSS();

    $timestamp time()+date("P");
    gmdate("YmdHis"$timestamp);
    $ordertime gmdate("YmdHis"$timestamp);

    // A query to INSERT data
    $query "INSERT INTO orders
     SET 
    clientname = '
    $cname'

    clientemail = '
    $cemail'
    "
    ;

    $result=mysql_query($query$link) or die("Died inserting login info into db.  Error returned if any: ".mysql_error());



        
    mail("$your_email""$your_subject""$your_message""From: $email");
        
    mail"$email""$auto_subject""$auto_message""$headers");
    }
    if (
    $pgm=="Tranferência Bancária") { 
    header("Location: /comprar-transferencia-bancaria.php"); 
    } elseif (
    $pgm=="Cartão de Crédito") { 
    header("Location: /comprar-cartao-de-credito.php"); 
    } elseif (
    $pgm=="Paypal") { 
    header("Location: /comprar-paypal.php"); 
    } elseif (
    $coupon=="A Dinheiro") { 
    header("Location: /comprar-a-dinheiro.php"); 
    }
    ?>

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    looks to me like you have a parse error

    PHP Code:
    //<----- ??????????????

        
    mail("$your_email""$your_subject""$your_message""From: $email");
        
    mail"$email""$auto_subject""$auto_message""$headers");


    did you turn off error reporting or something? bad idea...

  3. #3
    SitePoint Addict Johana Solendhal's Avatar
    Join Date
    Aug 2004
    Location
    Land of the free
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    UpS! Gracias clamcruher!

    Now I'm getting a "Header already sent" problem.

    Any idea how to fix this?

    here is my config.php file:

    PHP Code:
    <?

    //
    //E-MAIL SETTINGS
    //
    $headers "From: info@mysite.com"
    $headers .= "Content-Type: text/html; charset=iso-8859-1\n"

    //Your e-mail address (the address that the form gets sent to)
    $your_email "info@mysite.com";

    //Subject of e-mail sent to you
    $your_subject "New Contact";

    //Subject of confirmation e-mail sent to person submitting form
    $auto_subject " Contact";

    //Message in e-mail sent to you (can be left as it is or altered. \n denoted a line break)
    $your_message "CONTACT:\n\nName: $name\nEmail: $email\nSubject: $subject\nWeb Site: $website\nCompany: $company\nComments: $comments\n";

    $site_thanks "http://www.websitefocus.net/index.php?content=contactusthanks&nav=contact";

    //Message sent as confirmation (can be left as it is or altered. \n denoted a line break)
    $auto_message "<body link=\"#000000\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">---------------------------------------------------<br>WEBSITEFOCUS CONTACT<br>---------------------------------------------------<br><br>\n\nDear $name,<br><br>Your inquiry has been received. We will get back to you as soon as possible.<br><br>Best regards<br><br><a href='http://www.websitefocus.net'>http://www.websitefocus.net</a></font></body>";

    ?>

  4. #4
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Johana Solendhal
    UpS! Gracias clamcruher!

    Now I'm getting a "Header already sent" problem.

    Any idea how to fix this?

    here is my config.php file:

    PHP Code:
    <?

    //
    //E-MAIL SETTINGS
    //
    $headers "From: info@mysite.com"
    $headers .= "Content-Type: text/html; charset=iso-8859-1\n"

    //Your e-mail address (the address that the form gets sent to)
    $your_email "info@mysite.com";

    //Subject of e-mail sent to you
    $your_subject "New Contact";

    //Subject of confirmation e-mail sent to person submitting form
    $auto_subject " Contact";

    //Message in e-mail sent to you (can be left as it is or altered. \n denoted a line break)
    $your_message "CONTACT:\n\nName: $name\nEmail: $email\nSubject: $subject\nWeb Site: $website\nCompany: $company\nComments: $comments\n";

    $site_thanks "http://www.websitefocus.net/index.php?content=contactusthanks&nav=contact";

    //Message sent as confirmation (can be left as it is or altered. \n denoted a line break)
    $auto_message "<body link=\"#000000\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">---------------------------------------------------<br>WEBSITEFOCUS CONTACT<br>---------------------------------------------------<br><br>\n\nDear $name,<br><br>Your inquiry has been received. We will get back to you as soon as possible.<br><br>Best regards<br><br><a href='http://www.websitefocus.net'>http://www.websitefocus.net</a></font></body>";

    ?>
    Headers should be sent before any content is outputted in the browser.
    You could reload the page using a GET variable in your link, and run a check for that variable at the top of your script.

  5. #5
    SitePoint Addict Johana Solendhal's Avatar
    Join Date
    Aug 2004
    Location
    Land of the free
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ize, could you explain in simpler terms?

  6. #6
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Johana Solendhal
    Ize, could you explain in simpler terms?
    If you want to change the location via a header(), you have to make sure no HTML whatsoever is outputted to the browser.
    So no echo() or print() commands, nor static HTML.

    If you find this hard to achieve, consider using this:

    Code:
    <meta http-equiv="refresh" content="1; URL=http://www.example.com" />
    This will take 1 second before sending the browser to www.example.com.

  7. #7
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bad
    PHP Code:
    <html>
    <?php
    // will cause error, you output <html> first
    // even a single space or blank new line will cause an error
    // no output of any kind is allowed before sending headers
    header(...);

    ?>
    good
    PHP Code:
    <?php

    header
    (...);

    ?>
    <html>


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
  •