Announcement

Collapse
No announcement yet.

PHP Guru Please

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    PHP Guru Please

    Can someone see anything wrong in the below, driving me bloody nuts!

    Code:
    <?php
    
    //send email
    $headers .= "From: $email<>\r\n";
    //message body
    $recipient = "enquiries@websitedesigned.co.uk";	
    $message .= "I would like to receive the Smithfield E-letter" . "\n\n";	
    $message .= "Email: " . $email . "\n";
    //build email
    $body = $message;
    //sends email
    $subject = "E-Letter Request";
    mail($recipient, $subject, $body, $headers) or die("couldn't send the email"); 
    header("Location: http://www.smithfieldwine.com/acatalog/thank-you.html");
    ?>
    Any help much appreciated.

    #2
    i get:

    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\sandbox.php on line 13
    couldn't send the email
    what did you get?

    for mail to work, your server has to be set up properly. mine is a test server here on my laptop, so its bound to fail. but is yours online?

    perhaps your php has been external mail disabled by the mins?

    as you can see, php assumes an smtp server at port 25, do you ahve one on your server?

    Comment


      #3
      also, try it simple first.

      this will send a basic mail.

      Code:
      <?php
      // The message
      $message = "Line 1\nLine 2\nLine 3";
      
      // In case any of our lines are larger than 70 characters, we should use wordwrap()
      $message = wordwrap($message, 70);
      
      // Send
      mail('caffinated@example.com', 'My Subject', $message);
      ?>
      from
      http://uk2.php.net/function.mail

      Comment


        #4
        It was working perfectly on my test domain, site has now gone live on a separate hosting account and when the form is filled in with an email address, the email address does not come over.

        This was a feature on a site that i have redesigned and i was asked to add it to the new site, which i have done here in the left hand column as it was and as it was working fine on my test domain.

        Can hosting bugger this up, i know bugger all about php, it was a favour turning into a nightmare lol. To clarify when you fill in an email address on that site and submit, the following is received, with no email address:

        I would like to receive the Smithfield E-letter

        Email:


        I wish i knew php, stupid things like this really frustrate me.

        Comment


          #5
          Lee... why does it have to be in PHP? Does the host not have a mail form script that can be used, these are often bundled with the hosting package as default.


          Bikster
          SellerDeck Designs and Responsive Themes

          Comment


            #6
            thats true. formmail.pl sould really be used.

            Comment


              #7
              It doesn't Jonty, but ease and common sense said just replicate what they currently do, don't be too clever. I don't understand php and what can make it work or not work on a server, but it must be a hosting issue i would think, unless i've missed a glaring error.

              I have not sorted the hosting, i do not even know who it is with, experience tells me so far, than i won't get to know either.

              Comment


                #8
                I wish i knew php
                i wish i diddnt know it.

                PHP Code:
                if($gabriel!=$asleep) {$php=true$triedness++;} 

                Comment


                  #9
                  It seems to work for me. Did you fix it?

                  Mike
                  -----------------------------------------

                  First Tackle - Fly Fishing and Game Angling

                  -----------------------------------------

                  Comment


                    #10
                    It all works fine online Mike, its the resulting email that does not contain the email address you've supplied.

                    It just comes:

                    I would like to receive the Smithfield E-letter

                    Email:


                    Thats it.

                    Comment


                      #11
                      Is the 'From' field in the email being populated?

                      If not , then where is $email coming from? When I do something similar I have a line that says:

                      $email = stripslashes($HTTP_POST_VARS['Email1']);
                      Mike
                      -----------------------------------------

                      First Tackle - Fly Fishing and Game Angling

                      -----------------------------------------

                      Comment


                        #12
                        Originally posted by leehack
                        Can someone see anything wrong in the below, driving me bloody nuts!

                        Code:
                        <?php
                        
                        //send email
                        $headers .= "From: $email<>\r\n";
                        //message body
                        $recipient = "enquiries@websitedesigned.co.uk";	
                        $message .= "I would like to receive the Smithfield E-letter" . "\n\n";	
                        $message .= "Email: " . $email . "\n";
                        //build email
                        $body = $message;
                        //sends email
                        $subject = "E-Letter Request";
                        mail($recipient, $subject, $body, $headers) or die("couldn't send the email"); 
                        header("Location: http://www.smithfieldwine.com/acatalog/thank-you.html");
                        ?>
                        Any help much appreciated.
                        The first thing I can see is that $email isnt defined anywhere, if this code works fine on one system but not another I would guess that register globals is enabled on one but not the other.

                        You should explicitly get the variable from either the $_POST or $_GET global scope.

                        Another comment I would make is that the code in its current implementation is possibly vulnerable to XSS, you need to filter the email field to make sure it contains just a single valid email address.

                        See http://www.securephpwiki.com/index.php/Email_Injection for more details

                        Comment


                          #13
                          Originally posted by olderscot
                          Is the 'From' field in the email being populated?

                          If not , then where is $email coming from? When I do something similar I have a line that says:

                          Mike
                          Hi Mike

                          On my test domain and the old domain, the email came headed from the email address input, where it is now failing, it shows as coming from:

                          website@smithfieldwine.com

                          which is quite different, must be something going on with the host surely?

                          Comment


                            #14
                            OK! Enough is enough already.. Lee .. bin it off and use a form mail script .. stop p*****g into the wind!

                            I can say that as a friend


                            Bikster
                            SellerDeck Designs and Responsive Themes

                            Comment


                              #15
                              Originally posted by MarkActinic
                              The first thing I can see is that $email isnt defined anywhere, if this code works fine on one system but not another I would guess that register globals is enabled on one but not the other.

                              You should explicitly get the variable from either the $_POST or $_GET global scope.

                              Another comment I would make is that the code in its current implementation is possibly vulnerable to XSS, you need to filter the email field to make sure it contains just a single valid email address.

                              See http://www.securephpwiki.com/index.php/Email_Injection for more details
                              Hi Mark

                              Thanks for your help.

                              Form on the site is:

                              Code:
                              <form action="http://www.smithfieldwine.com/form/smithfield-eletter.php" method="get">
                              <input name="email" type="text" size="18" id="email"><input type="submit" name="Submit" value="Submit">
                              </form>
                              And the code is as provided.

                              I know nothing about php. i was just asked to replicate what was on the old site onto the new site, during testing it worked on the old site, it worked on my test site and has only failed since it went live on a new domain. A complete mockery of me doing this early and testing it.

                              What the hell has happened i do not know, i will try and read your link when i get sometime, thank you for your info.

                              Comment

                              Working...
                              X