Results 1 to 5 of 5

Thread: mail and alert in PHP

  1. #1
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default mail and alert in PHP

    Hi,guys! I have a PHP script to send mail and prompt out alert if successfully sent.However,the alert is not displayed and all the form value become blank.How can I display alert without having a blank page?

    Secondly,the mailing script seems having some flaws,if form submitted,the previous sent form will be sent once again into the mailbox.What went wrong actualy?Thanks for you guys help!

    PHP Code:

    <?php
       
      $email 
    $_GET[email];
      
    $mailto "yourmail@mail.com";
      
    $mailsubj "Enquiry sent by visitor";
      
    $mailhead "From: $email";

      
    reset ($_GET);

      
    $mailbody "You have an enquiry from website:\n";

      while (list (
    $key$val) = each ($_GET)) {
            if(
    $key != 'submit'
            
    $mailbody .= "$key : $val\n"; }
          
      
    ini_set("SMTP",mail.yourmailserver.com.my);
      
    ini_set("smtp_port",25);
      
    ini_set("sendmail_from",$email);  
      
      
    $javascript "<script type=\"text/javascript\">";
      
      if (
    mail($mailto,$mailsubj,$mailbody,$mailhead)) {
         
    $javascript .= 'alert(\'Thank you for your enquiry, we shall contact you soon.\')';
    } else {
         
    $javascript .= 'alert(\'Email cannot be delivered.\')';
    }  
         
    $javascript .= '</script>';
       
    ?>
    Code:
    <FORM NAME="enquiry" ACTION="<?php echo htmlentities($HTTP_SERVER_VARS['PHP_SELF']); ?>" METHOD="GET">
    Last edited by devil_vin; 02-15-2008 at 10:30 AM.

  2. #2
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    I can see one problem, you never executed $javascript It is only a variable. At the end of your document put:
    Code:
    echo $javascript;
    And the reason that all the feilds become blank is that you are basicly refreshing the page. Not shure why it is not sending the email, but add this, just to check to see if it is going through (in bold):
    Code:
    if(mail($mailto,$mailsubj,$mailbody,$mailhead)) {
         echo "MAIL WENT THROUGH";
         $javascript .= 'alert(\'Thank you for your enquiry, we shall contact you soon.\')';
    } else {
    Not shure why it does what you said but.......
    Hope this helps,
    Last edited by fileserverdirect; 02-17-2008 at 01:53 AM.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  3. #3
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    I believe he wants it to be like an Ajax request, so it never refreshes. File, just curious, why do you spell sure "shure"?

  4. #4
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    I type very fast...
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You should get a recent browser, most of them have spell-check features nowadays.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •