halojoy-

I added this code to the script but it doesnt seem to be working:

if (@mail($mailto, $subject, $message, $header)) {

header("Location: $redirect");
} else {
// This echo's the error message if the email did not send.
// You could change the text in between the <p> tags.
echo('<p>Mail could not be sent. Please use your back button to try again.</p>');
}
function MAIL_NVLP($fromname, $fromaddress, $toname, $toaddress, $subject, $message)
{
   // Copyright ? 2005 ECRIA LLC, [url]http://www.ECRIA.com[/url]
   // Please use or modify for any purpose but leave this notice unchanged.
   $headers  = "MIME-Version: 1.0\n";
   $headers .= "Content-type: text/plain; charset=iso-8859-1\n";
   $headers .= "X-Priority: 3\n";
   $headers .= "X-MSMail-Priority: Normal\n";
   $headers .= "X-Mailer: php\n";
   $headers .= "From: \"".$fromname."\" <".$fromaddress.">\n";
   return mail($toaddress, $subject, $message, $headers);
}
    // if mail was sent correctly - redirect to somewhere
    // send mail without making header
    if ( mail($mailto, $subject, $message, $header)) { 
    
    header("Location: $redirect"); 
    }
    
    
    // else make some header and send email
    else{
    
    // header = xxxxxxxxxxxxxxxx
    mail( $toaddress, $subject, $message, $header );
    }

    You use mail() function 2 times in this.
    I guess you now can change your script to work.
    Not just copy and paste, and hope for best.

    Use YOUR brains, man!
    Because I need to use mine, for myself.
    Sometimes...

      halojoy-

      Bare with me. I just looked at php for the first time a few days ago when posting this question, so its completely foreign to me. I'm still lost about what you pointed out in your post.

      So. should I basically remove these lines:

      if (@mail($mailto, $subject, $message, $header)) { 
      
      header("Location: $redirect"); 
      } else { 
      // This echo's the error message if the email did not send. 
      // You could change the text in between the <p> tags. 
      echo('<p>Mail could not be sent. Please use your back button to try again.</p>'); 
      } 
      

      The end result, looking like this:

      function MAIL_NVLP($fromname, $fromaddress, $toname, $toaddress, $subject, $message) 
      { 
         // Copyright ? 2005 ECRIA LLC, <a href="http://www.ECRIA.com" target="_blank">[url]http://www.ECRIA.com[/url]</a> 
         // Please use or modify for any purpose but leave this notice unchanged. 
         $headers  = "MIME-Version: 1.0\n"; 
         $headers .= "Content-type: text/plain; charset=iso-8859-1\n"; 
         $headers .= "X-Priority: 3\n"; 
         $headers .= "X-MSMail-Priority: Normal\n"; 
         $headers .= "X-Mailer: php\n"; 
         $headers .= "From: \"".$fromname."\" <".$fromaddress.">\n"; 
         return mail($toaddress, $subject, $message, $headers); 
      }
      

      PS- By the way, I'm half Swedish πŸ™‚

        Half Swedish. Makes us belong together. At least for 50%πŸ˜ƒ
        Your location: ( looks very interesting, have never been there, yet )

        that function looks better
        Have you tried it out?

        so we know what errors to fix πŸ†’
        I still havent wrote a PHP script that worked right away.
        I wonder if anyone has ....

          halojoy-

          Ya, gave it a shot but didnt work. Now I'm really confused πŸ™‚

          Here is the new code I entered but I'm still not getting any email notification back to me:

          <?php
          // see if newsletter was checked
          $email = trim(@$_POST['email'] );
          //@suppresses the warning when email is not set
          if ( isset($_POST['newsletter']) && !empty($email) ) {
          $filename = 'subscribers.txt';
          $name_arr = explode( ' ', $_POST['FullName'] );
                  $first_name = $name_arr[0];
                  $file_arr = file($filename);
                  $found = false;
                  foreach ($file_arr as $value) {
                       if (strpos($value, $_POST['email'])!==FALSE ) {
                       //this change was necessary: check manual for strpos
                           $found = true;
                          break;
                    }
                  }
                  if (!$found) {
                   $fp = fopen($filename, 'a+');//a+ means "create when it's not present"
                   fwrite($fp, $_POST['email'] . ',' . $_POST['FullName'] . "\n");
                   fclose($fp);
                    }
           }
          // this redirect is whether newsletter was checked or not
          $URL = "http://shapefit.com/thankyou-newsletter.html";
          header ("Location: $URL");
          
          $mailto = "me@mydomain.com"; 
          $subject = "Contact Form"; 
          
          
          foreach($HTTP_POST_VARS as $key => $value) { 
          
          $message .= $key . ': ' . $value; 
          $message .= "\n"; //Note the double quotes
          
          } 
          ?>
          

          I'm actually out here in sunny South Florida (windy also). I need to schedule some time to visit the home country. Never been there πŸ™‚

            <?php error_reporting (E_ALL);
            // this is OBLIGATORY, DEFAULT and RECOMMENDED topline
            // whenever working with devlopment of php scripts
            // DEBUG setting in php, we can call it

            So I wont bother answer your stuff
            until I get some reports form PHP.exe program

            Making guessings straight out of the blue ( dont know if that is good english )
            has never been my strongest ability.
            :p :p

            halojoy swedish -
            hans bÀsta gren Àr inte 'vilda gissningar'
            his best disciplin is not 'wild guessings'

              so,
              where in this script does you send your email?
              using this function you posted here?

              mail ( $as, $af, $sg , $header );
              hasto be performed to send mail
              that is one thing for certain!

                Originally posted by bad959fl
                I thought it was this line:

                $mailto = "me@mydomain.com";

                $mailto = ...
                makes a string variable, that can be printed or sent by mail, representing where to mail should be sent
                notice the $ before this variable, or any variable

                mail ( $mailto, $af, $sg , $header );
                notice: no $ before mail( )
                this is a function, something that has a function to do

                in this case, function mail ( $mailto, $af, $sg, $header )
                takes the stuff, 4 variables, that represnt 4 strings, and by these values
                sends a mail

                  halojoy-

                  Ok, I'm just about there πŸ™‚ I have different scripts that seem to do everything I need but I'm not sure how to combine them to work correctly.

                  Here is the code to email me the with the client's email address in the "From:" field when I receive the message:

                  <?php
                  $sender = $email;
                  $target = "me@myemail.com";
                  $subject = "New subscriber added to the newsletter";
                  $message = "Enter your message here including desired $variables and formatting from the subscription form such as
                  subscriber: $subscriber\ne-mail: $email\n and the like.";
                  $headers = "From: $sender\n";
                  $headers .= "MIME-Version: 1.0\r\n";
                  $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
                  // send the message and give the confirmation back to the submitter
                  mail ($target, $subject, $message, $headers);
                  ?>
                  

                  Here is the code to send me all of the form's input items (text boxes, dropdowns, check boxes, etc.):

                  <?php 
                  // ************Begin Configure*************** 
                  //Put where you want the email to go 
                  $mailto = "me@myemail.com"; 
                  //Put where to redirect to after sending the email 
                  $redirect = "thankyou-newsletter.html"; 
                  // ************End Configure**************** 
                  
                  $headers = "From: $sender\n";
                  $headers .= "MIME-Version: 1.0\r\n";
                  $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
                  
                  mail ($target, $subject, $message, $headers);
                  
                  foreach($HTTP_POST_VARS as $key => $value) { 
                  
                  $message .= $key . ': ' . $value; 
                  $message .= "\n"; //Note the double quotes
                  
                  } 
                  if (@mail($mailto, $subject, $message)) { 
                  
                  header("Location: $redirect"); 
                  } else { 
                  // This echo's the error message if the email did not send. 
                  // You could change the text in between the <p> tags. 
                  echo('<p>Mail could not be sent. Please use your back button to try again.</p>'); 
                  } 
                  ?>
                  

                  Finally, here is the core of the code which checks for duplicate email addresses and if not found, adds the email to a text file:

                  <?php 
                  // see if newsletter was checked 
                  $email = trim(@$_POST['email'] ); 
                  //@suppresses the warning when email is not set 
                  if ( isset($_POST['newsletter']) && !empty($email) ) { 
                  $filename = 'subscribers.txt'; 
                  $name_arr = explode( ' ', $_POST['FullName'] ); 
                          $first_name = $name_arr[0]; 
                          $file_arr = file($filename); 
                          $found = false; 
                          foreach ($file_arr as $value) { 
                               if (strpos($value, $_POST['email'])!==FALSE ) { 
                               //this change was necessary: check manual for strpos 
                                   $found = true; 
                                  break; 
                            } 
                          } 
                          if (!$found) { 
                           $fp = fopen($filename, 'a+');//a+ means "create when it's not present" 
                           fwrite($fp, $_POST['email'] . ',' . $_POST['FullName'] . "\n"); 
                           fclose($fp); 
                            } 
                   } 
                  // this redirect is whether newsletter was checked or not 
                  $URL = "thankyou-newsletter.html"; 
                  header ("Location: $URL"); 
                  ?>
                  

                  Any thoughts how I can mix all these to have all elements work. Thanks!

                    15 days later

                    I'm just about finished with this script but I need a little more help. Here is the current code:

                    <?php 
                    // see if newsletter was checked 
                    $email = trim(@$_POST['email'] ); 
                    //@suppresses the warning when email is not set 
                    if ( isset($_POST['newsletter']) &&!empty($email) ) { 
                    $filename = 'subscribers.txt'; 
                    $name_arr = explode( ' ', $_POST['FullName'] ); 
                    $first_name = $name_arr[0]; 
                    $file_arr = file($filename); 
                    $found = false; 
                    foreach ($file_arr as $value) { 
                    if (strpos($value, $_POST['email'])!==FALSE ) { 
                    //this change was necessary: check manual for strpos 
                    $found = true; 
                    break; 
                    } 
                    } 
                    if (!$found) { 
                    $fp = fopen($filename, 'a+');//a+ means "create when it's not present" 
                    fwrite($fp, $_POST['email'] . ',' . $_POST['FirstName'] . "\n"); 
                    fclose($fp); 
                    } 
                    } 
                    
                    //send the email to the admin 
                    $headers = ''; 
                    $headers .= "MIME-Version: 1.0\n"; 
                    $headers .= "Content-type: text/html; charset=iso-8859-1\n"; 
                    $headers .= "X-Priority: 1\n"; 
                    $headers .= "X-MSMail-Priority: High\n"; 
                    $headers .= "X-Mailer: PHP\n"; 
                    $headers .= "From: \"".$_POST['FullName']."\" <".$_POST['email'] .">\n"; 
                    //$headers .= "Bcc: $some_address\n"; 
                    $to      = "me@myemail.com"; 
                    $subject = "New user signed up"; 
                    $message = ''; 
                    //add elements as desired 
                    foreach($HTTP_POST_VARS as $key => $value) { 
                    
                      $message .= $key . ": " . $value . "\r\n"; //Note the double quotes 
                    
                    } 
                    
                    mail ($to, $subject, $message, $headers); 
                    
                    // this redirect is whether newsletter was checked or not 
                    $URL = "thankyou-newsletter.html"; 
                    header ("Location: $URL"); 
                    ?>
                    

                    The thing I need help with is when the form field results come back to me via email, they consist of 1 long line of wrapped text. How do do I add a break on each line (form field) so its easier to read? Here is an example:

                    Currently:

                    FirstName: ken email: ken@yahoo.com Referred: yahoo Searching: workouts subscribe_x: 25 subscribe_y: 10

                    I would like the results to look like this in the email:

                    FirstName: ken

                    email: ken@yahoo.com

                    Referred: yahoo

                    Searching: workouts

                    subscribe_x: 25 subscribe_y: 10

                    Thanks!

                      <?php
                      
                      $message = ''; 
                      //add elements as desired 
                      foreach($HTTP_POST_VARS as $key => $value) { 
                      
                        $message .= $key . ": " . $value . "\r\n"; //Note the double quotes 
                      
                      } 
                      
                      // maybe we should add some breaks <br>
                      // uses function newline to break, add <br> for each \n
                      $message = nl2br( $message );
                      
                      ?>

                      Here is where email body message is built up
                      for to be sent in mail()

                      We may do some changes here, or even earlier in script

                      /halojoy thinks

                        I ended up making it work pefectly with this change:

                        $message .= $key . ": " . $value . "<p />"; //Note the double quotes 
                        

                        My last issue with this form is make sure the client enters each form field. Since I have over 20 forms with different numbers of fields for each one, whats the best way to implement this so if they dont fill out a field, they will receive an error message?

                          Always put an exit after a header you use to relocate someone or the script will keep executing statements below until the connection terminates. Or use it in the form

                          die(header('Location: ....'));
                            bad959fl wrote:

                            I ended up making it work pefectly

                            • My last issue with this form is make sure the client enters each form field.
                            • Since I have over 20 forms with different numbers of fields for each one
                              Whats the best way to implement this so if they dont fill out a field,
                              they will receive an error message?

                            make a forum search:

                            http://www.phpbuilder.com/board/search.php
                            -> form message fill <-

                            must be 200 examples we have written for you and other guys

                            :bemused:

                            maybe 20 only last week in this PHP Help forum

                            πŸ˜ƒ πŸ˜ƒ

                            .

                              I also want to place the "subscribers.txt" file in a secured area (cgi-bin) to protect the email addresses. I moved this file over and updated the code:

                              $filename = '/home/httpd/vhosts/domain.com/cgi-bin/subscribers.txt';
                              

                              However, it errors out now. Is there a way to make this work?

                                Create a new folder with correct CHMOD permissions and .htaccess
                                beside /cgi-bin/ folder

                                $filename = '/home/httpd/vhosts/domain.com/cgi-bin/subscribers.txt';
                                use this instead
                                $filename = '/home/httpd/vhosts/domain.com/my_secure/subscribers.txt';

                                you can also run your 'phpinfo.php'
                                <?php
                                phpinfo();
                                ?>

                                to see what folders php uses, for example where
                                your php.ini store sessions 'sessions path'

                                maybe you should make some new php-folders
                                and change php.ini accordingly ?

                                  Write a Reply...