www.webdeveloper.com
Results 1 to 5 of 5

Thread: Mail Form + PHP + Java Script Alert error!

  1. #1
    Join Date
    Aug 2005
    Posts
    32

    Mail Form + PHP + Java Script Alert error!

    Hello,

    I have a simple mail form that is using the following php code to send the mail:

    PHP Code:
    <?php
    @extract($_POST);
    $subject="Formulário do site";
    $nome stripslashes($nome);
    $morada stripslashes($morada);
    $email stripslashes($email);
    $telefone stripslashes($telefone);
    $text stripslashes($text);
    $msg "
    Nome : 
    $nome \n
    Morada : 
    $morada \n
    Email : 
    $email \n
    Telefone : 
    $telefone \n
    Mensagem : 
    $text \n";

    mail("mjorge@gmail.com",$subject,$msg,"From: $nome <$email>");
    $myAlert="Email sent!!!";
    echo 
    "<script langauge=\"javascript\">alert(\"".$myAlert."\");</script>"
    header("location:contactos.php");
    ?>
    The idea is that when the user click the send button a javascript alert will popUp saying that the mail was sent.

    The prob is that this code is giving me the following error after pressing the send button:

    "Warning: Cannot modify header information - headers already sent by (output started at /home/vitormjl/public_html/process.php:18) in /home/vitormjl/public_html/process.php on line 19"

    Can anyone help please?

  2. #2
    Join Date
    May 2006
    Location
    the netherlands
    Posts
    454
    that's because you have output before the header() call, which isn't allowed for obvious reasons.

  3. #3
    Join Date
    Aug 2005
    Posts
    32
    Thank for the reply "theMarty"

    However i´m still stuck on this. I´m still newbie at php...

    Can u please tell me how to fix this?

    Many thanks.

  4. #4
    Join Date
    May 2006
    Location
    the netherlands
    Posts
    454
    whenever you request a page from a server, that page is sent back to you (your browser), including a whole bunch of headers. For example, the headers can tell the browser that the page doesn't exist (a 404) or that a page has been moved to a new location, so the browser can immediately redirect, etc. etc.
    With the header() function you can alter these headers somewhat. But, of course this requires that no output has been sent to the users browser yet. Because, any data sent to the user, will have to be accompanied by some headers.

    So, either you have to solve this by outputting a whole page, including the javascript alert and a meta-tag that redirects the browser, or you have to pass along the message to the next page (storing it in a GET var or in the SESSION)

  5. #5
    Join Date
    Aug 2005
    Posts
    32
    Ok, thanks. I guess i solved the problem.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles