Why can't I get this mail() script to work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ringorocks25
    New Member
    • Aug 2010
    • 4

    Why can't I get this mail() script to work

    I have a flash template with a contact page when you put all the information in the fields and click send it says sent like everything works. After that I check my mail and there is nothing there. I have tested the webserver it is php compatible. I also created a mini test string and was able to send and recieve a test email using that small string. I'll post the action script in flash first then the php code. Id appreciate someone telling me what I'm doing wrong.

    Thanks

    Heres the action script in flash
    Code:
    function clearField()
    {
        txtField1.text = label1;
        txtField2.text = label2;
        txtField3.text = label3;
        txtField4.text = label4;
        txtField5.text = label5;
        Selection.setFocus("_focus");
    } // End of the function
    label1 = "";
    label2 = "";
    label3 = "";
    label4 = "";
    label5 = "Message:";
    countField = 5;
    clearField();
    var arrayLabel = new Array();
    for (i = 1; i < countField + 1; i++)
    {
        txtField = this["txtField" + i];
        txtField.index = i;
        arrayLabel[i] = this["label" + i];
        txtField.tabIndex = i;
        txtField.onSetFocus = function ()
        {
            if (this.text == arrayLabel[this.index])
            {
                this.text = "";
            } // end if
        };
        txtField.onKillFocus = function ()
        {
            if (this.text == "")
            {
                this.text = arrayLabel[this.index];
            } // end if
        };
    } // end of for
    btnClear.onRollOver = function ()
    {
        this.gotoAndPlay("over");
    };
    btnClear.onRollOut = btnClear.onReleaseOutside = function ()
    {
        this.gotoAndPlay("out");
    };
    btnClear.onRelease = function ()
    {
        clearField();
    };
    btnSubmit.onRollOver = function ()
    {
        this.gotoAndPlay("over");
    };
    btnSubmit.onRollOut = btnSubmit.onReleaseOutside = function ()
    {
        this.gotoAndPlay("out");
    };
    btnSubmit.onRelease = function ()
    {
        if (_parent.contactform.txtField1.text == label1 || _parent.contactform.txtField2.text == label2 || _parent.contactform.txtField3.text == label3 || _parent.contactform.txtField4.text == label4 || _parent.contactform.txtField5.text == label5)
        {
            gotoAndStop(3);
        }
        else
        {
            _parent.contactform.loadVariables("email.php", "POST");
            gotoAndStop(2);
        } // end else if
    };
    stop ();
    Heres the php script
    Code:
    <?php
    //Type the receiever's e-mail address
    $emailAddress = "brian@sbsitedesigns.com";
    //Type your Site Name
    $siteName = "SBSiteDesigns.com";
    
    $contact_name = $_POST['name'];
    $contact_email = $_POST['email'];
    $contact_subject = $_POST['subject'];
    $contact_message = $_POST['message'];
    
    if( $contact_name == true ) {
    	$sender = $contact_email;
    	$receiver = $emailAddress;
    	$client_ip = $_SERVER['REMOTE_ADDR'];
    
    	$email_body = "The Name Of The Sender: $contact_name \nEmail: $sender \n\nSubject: $contact_subject
    \n\nMessage: \n\n$contact_message \n\nIP ADDRESS: $client_ip \n\n$siteName";
    
    	$emailAutoReply = "Hi $contact_name, \n\nWe have just received your E-Mail. We will get
    in touch in a few days. Thank you!  \n\n$siteName ";
    
    	$extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion();
    	$autoReply = "From: $receiver\r\n" . "Reply-To: $receiver \r\n" . "X-Mailer: PHP/" . phpversion();
    
    	mail( $sender, "Auto Reply: $contact_subject", $emailAutoReply, $autoReply );
    
    	if( mail( $receiver, "New E-Mail - $contact_subject", $email_body, $extra ) ) {
    		echo "success=yes";
    	} else {
    		echo "success=no";
    	}
    }
    ?>
    Thanks in advance
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    Just run this in a new php file to see if your mail is configured correctly: (remember to put your email in the $to, and also check your spam box)
    Code:
    <?php
     $to = "recipient@example.com";
     $subject = "Email test";
     $body = "Testtesttest";
     if (mail($to, $subject, $body)) {
       echo("<p>Message successfully sent!</p>");
      } else {
       echo("<p>Message delivery failed...</p>");
      }
     ?>

    Comment

    • ringorocks25
      New Member
      • Aug 2010
      • 4

      #3
      Thats very similar to the "mini" script I wrote and tested with, but I ran yours anyways. Same thing it sent, and I received, so it has to be something in the mail.PHP script itself.
      Thanks for your replay

      Comment

      • TheServant
        Recognized Expert Top Contributor
        • Feb 2008
        • 1168

        #4
        Try:
        Code:
        <?php
        //Type the receiever's e-mail address
        $emailAddress = "brian@sbsitedesigns.com";
        //Type your Site Name
        $siteName = "SBSiteDesigns.com";
         
        $contact_name = $_POST['name'];
        $contact_email = $_POST['email'];
        $contact_subject = $_POST['subject'];
        $contact_message = $_POST['message'];
        
        	/* -- Test -- */
        echo "Contact Name: $contact_name< br/>";
        echo "Contact Email: $contact_email< br/>";
        echo "Contact Subject: $contact_subject< br/>";
        echo "Contact Message: $contact_message< br/>< br/>";
         
        if( $contact_name == true ) {
            $sender = $contact_email;
            $receiver = $emailAddress;
            $client_ip = $_SERVER['REMOTE_ADDR'];
         
            $email_body = "The Name Of The Sender: $contact_name \nEmail: $sender \n\nSubject: $contact_subject
        \n\nMessage: \n\n$contact_message \n\nIP ADDRESS: $client_ip \n\n$siteName";
         
            $emailAutoReply = "Hi $contact_name, \n\nWe have just received your E-Mail. We will get
        in touch in a few days. Thank you!  \n\n$siteName ";
         
            $extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion();
            $autoReply = "From: $receiver\r\n" . "Reply-To: $receiver \r\n" . "X-Mailer: PHP/" . phpversion();
         
        	/* -- Test -- */
        	echo "Email Body: $email_body< br/>";
        	echo "Auto Reply Email: $emailAutoReply< br/>";
        	echo "Extra: $extra< br/>";
        	echo "Auto Reply: $autoReply< br/>";
        	
        
         
         
            mail( $sender, "Auto Reply: $contact_subject", $emailAutoReply, $autoReply );
         
            if( mail( $receiver, "New E-Mail - $contact_subject", $email_body, $extra ) ) {
                echo "success=yes";
            } else {
                echo "success=no";
            }
        }
        ?>
        I have just put in some echo's at some points to see if your variables are what you expect. I am hoping it's something easy like $_POST not being sent correctly.

        Out of interest, does your Auto Reply mail work? Or are both emails not working?

        Comment

        • ringorocks25
          New Member
          • Aug 2010
          • 4

          #5
          Well its not as easy as I'd hoped. It's down right frustrating! That code you gave me didn't work. To answer your question (first thanks for your help!) I'm not receiving the auto reply or the notification e-mail

          Comment

          • TheServant
            Recognized Expert Top Contributor
            • Feb 2008
            • 1168

            #6
            What do you mean it didn't work? There was no output?

            If so, then I'm going to guess it's how you're calling the script.

            Comment

            • ringorocks25
              New Member
              • Aug 2010
              • 4

              #7
              The last script that you gave me didn't send me a reply or notification. I have checked and rechecked the actionscript and I'm at a loss. I guess I'll have to just use another script. Thanks for your help.

              Comment

              • TheServant
                Recognized Expert Top Contributor
                • Feb 2008
                • 1168

                #8
                I put in a bunch of echo's to see if it was everything you expected. Did none of those print?

                Comment

                • Namik
                  New Member
                  • Sep 2010
                  • 3

                  #9
                  What I did to the actionScript is add a getURL to the end of it and pointed it to the email.php page.

                  This is the result I got.

                  Contact Name: < br/>Contact Email: < br/>Contact Subject: < br/>Contact Message: < br/>< br/>

                  So basically nothing.

                  I tested the email PHP which you had posted earlier and it was all fine. Recieved email.

                  The only problem I think is the actionScript posting the variables to the email.php

                  Can you help mate?

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    You should turn on error-reporting.

                    Code:
                    // At the very top of your code
                    error_reporting(-1);
                    ini_set('display_errors', 1);

                    Comment

                    • Namik
                      New Member
                      • Sep 2010
                      • 3

                      #11
                      Where would I see these errors?

                      I think it's the flas ActionScript posting to the PHP which is the problem.

                      I can't get around how to fix it though.

                      Comment

                      • Namik
                        New Member
                        • Sep 2010
                        • 3

                        #12
                        I fixed the problem. Apparently in the AS line 69 there was a function which didn't allow the sending of data gotoAndstop(2);

                        so I added a this function so it would send the data and when it received confirmation from the server it would stop.

                        Code:
                        _parent.contactform.loadVariables("email.php", this, "POST");
                        		this.onData = function() {
                        			gotoAndStop(2);
                        		};

                        Comment

                        • johnpham
                          New Member
                          • Feb 2011
                          • 1

                          #13
                          Hi Namik,
                          Can you please let me know how you get it to work? Cuz i tried copy the part you added and i was never able to get the button submit to activate. If you could post up the entire code that is working for you that would be very helpful.
                          thanks
                          john

                          Comment

                          Working...