16 Replies Latest reply on Jan 25, 2009 11:18 AM by Newsgroup_User

    php email

    brywilson88 Level 1
      I have a php page that captures user’s information (they input) then emails it to me.

      However, when I receive it, it shows that it is sent from : Doep76Fdep3tdn312.shr.phx4.secureserver.net.

      Is there a way to change this to better reflect where the message is from?
        • 1. Re: php email
          Level 7
          What form processing script are you using?

          --
          Murray --- ICQ 71997575
          Adobe Community Expert
          (If you *MUST* email me, don't LAUGH when you do so!)
          ==================
          http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
          http://www.dwfaq.com - DW FAQs, Tutorials & Resources
          ==================


          "brywilson88" <webforumsuser@macromedia.com> wrote in message
          news:glcnhk$gfk$1@forums.macromedia.com...
          >I have a php page that captures user?s information (they input) then emails
          >it
          > to me.
          >
          > However, when I receive it, it shows that it is sent from :
          > Doep76Fdep3tdn312.shr.phx4.secureserver.net.
          >
          > Is there a way to change this to better reflect where the message is from?
          >
          >

          • 2. Re: php email
            Chepe Nicoli Level 1
            Maybe this can help:

            $headers = "From: TheNameHere <the_email@here.com>\r\n";
            $headers .= "Cc: CopyToNameHere <CopyTo_email@here.com>\r\n";

            mail("Recipient@emailHere.com","Subject Here","Message here",$headers);
            • 3. Re: php email
              brywilson88 Level 1
              Murray -

              Code - just how Dreamweaver set it up
              <?php

              $my_email = "myemail@mymail.com";

              $errors = array();

              if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

              if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
              {

              $_REQUEST['email'] = trim($_REQUEST['email']);

              if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

              }

              if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}

              function recursive_array_check_blank($element_value)
              {

              global $set;

              if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
              else
              {

              foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

              }

              }

              recursive_array_check_blank($_REQUEST);

              if(!$set){$errors[] = "You cannot send a blank form";}

              unset($set);

              if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

              if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}

              function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

              $message = build_message($_REQUEST);

              $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you!";

              $message = stripslashes($message);

              $subject = "Your Information";

              $headers = "From: " . $_REQUEST['email'];
              $headers .= PHP_EOL;
              $headers .= "Return-Path: " . $_REQUEST['email'];
              $headers .= PHP_EOL;
              $headers .= "Reply-To: " . $_REQUEST['email'];

              mail($my_email,$subject,$message,$headers);

              ?>

              Thanks - just not really sure where to start.
              • 4. Re: php email
                brywilson88 Level 1
                Chepe Nicoli - thanks - I will play with this a bit and see what happens
                • 5. Re: php email
                  Level 7
                  I am certain that DW did not write this code for you - was it an installed
                  extension?

                  You have -

                  if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) ==
                  "WIN") ? "\r\n" : "\n");}

                  But I am equally certain that this will cause problems since email headers
                  must never be terminated by only "\n". Declude, for one, will reject such
                  messages as virus containing, and the intended recipient will never see
                  them.

                  Anyhow, in the emails that you *do* receive, when you REPLY to the incoming
                  email, what email address is being used for the reply address? Is it
                  "Doep76Fdep3tdn312.shr.phx4.secureserver.net"? If so, then there is a
                  problem with your processing of the 'email' field. How is that field named
                  on the page containing the form? Might it be 'e-mail', or 'Email"?

                  --
                  Murray --- ICQ 71997575
                  Adobe Community Expert
                  (If you *MUST* email me, don't LAUGH when you do so!)
                  ==================
                  http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                  http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                  ==================


                  "brywilson88" <webforumsuser@macromedia.com> wrote in message
                  news:glfa9q$llb$1@forums.macromedia.com...
                  > Murray -
                  >
                  > Code - just how Dreamweaver set it up
                  > <?php
                  >
                  > $my_email = "myemail@mymail.com";
                  >
                  > $errors = array();
                  >
                  > if(count($_COOKIE)){foreach(array_keys($_COOKIE) as
                  > $value){unset($_REQUEST[$value]);}}
                  >
                  > if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
                  > {
                  >
                  > $_REQUEST['email'] = trim($_REQUEST['email']);
                  >
                  > if(substr_count($_REQUEST['email'],"@") != 1 ||
                  > stristr($_REQUEST['email'],"
                  > ")){$errors[] = "Email address is invalid";}else{$exploded_email =
                  > explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) ||
                  > strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] =
                  > "Email address is invalid";}else{if(substr_count($exploded_email[1],".")
                  > ==
                  > 0){$errors[] = "Email address is invalid";}else{$exploded_domain =
                  > explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[]
                  > =
                  > "Email address is invalid";}else{foreach($exploded_domain as
                  > $value){if(strlen($value) > 63 ||
                  > !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is
                  > invalid";
                  > break;}}}}}}
                  >
                  > }
                  >
                  > if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])
                  > &&
                  > stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You
                  > must
                  > enable referrer logging to use the form";}
                  >
                  > function recursive_array_check_blank($element_value)
                  > {
                  >
                  > global $set;
                  >
                  > if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
                  > else
                  > {
                  >
                  > foreach($element_value as $value){if($set){break;}
                  > recursive_array_check_blank($value);}
                  >
                  > }
                  >
                  > }
                  >
                  > recursive_array_check_blank($_REQUEST);
                  >
                  > if(!$set){$errors[] = "You cannot send a blank form";}
                  >
                  > unset($set);
                  >
                  > if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}
                  >
                  > if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) ==
                  > "WIN") ? "\r\n" : "\n");}
                  >
                  > function
                  > build_message($request_input){if(!isset($message_output)){$message_output
                  > ="";}if(!is_array($request_input)){$message_output =
                  > $request_input;}else{foreach($request_input as $key =>
                  > $value){if(!empty($value)){if(!is_numeric($key)){$message_output .=
                  > str_replace("_"," ",ucfirst($key)).":
                  > ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .=
                  > build_message($value).", ";}}}}return rtrim($message_output,", ");}
                  >
                  > $message = build_message($_REQUEST);
                  >
                  > $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you!";
                  >
                  > $message = stripslashes($message);
                  >
                  > $subject = "Your Information";
                  >
                  > $headers = "From: " . $_REQUEST['email'];
                  > $headers .= PHP_EOL;
                  > $headers .= "Return-Path: " . $_REQUEST['email'];
                  > $headers .= PHP_EOL;
                  > $headers .= "Reply-To: " . $_REQUEST['email'];
                  >
                  > mail($my_email,$subject,$message,$headers);
                  >
                  > ?>
                  >
                  > Thanks - just not really sure where to start.
                  >

                  • 6. php email
                    brywilson88 Level 1
                    You may be right, but I don't remember getting an extension for this.

                    Not sure what you are asking for. When I do reply, it does show the Doep76Fdep3tdn312.shr.phx4.secureserver.net as the address.

                    My forms page just send the captured information to a "success" page - the success page actually submits the information to my hosting company which sends the email - I think this is how it works. The code posted in last post was from the success page.
                    • 7. Re: php email
                      Level 7
                      > Doep76Fdep3tdn312.shr.phx4.secureserver.net

                      This looks like the default email used when NO email address is used.
                      Please show me the code for the email entry field in the form. It LOOKs
                      like you are not properly referencing the contents of that field. Or is
                      there even a field where someone would enter their email address?

                      --
                      Murray --- ICQ 71997575
                      Adobe Community Expert
                      (If you *MUST* email me, don't LAUGH when you do so!)
                      ==================
                      http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                      http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                      ==================


                      "brywilson88" <webforumsuser@macromedia.com> wrote in message
                      news:gli4r6$59i$1@forums.macromedia.com...
                      > You may be right, but I don't remember getting an extension for this.
                      >
                      > Not sure what you are asking for. When I do reply, it does show the
                      > Doep76Fdep3tdn312.shr.phx4.secureserver.net as the address.
                      >
                      > My forms page just send the captured information to a "success" - the
                      > success
                      > page actually submits the information to my hosting company which sends
                      > the
                      > email - I think this is how it works. The code posted in last post was
                      > from
                      > the success page.
                      >

                      • 8. Re: php email
                        brywilson88 Level 1
                        What I am trying to do is:

                        1) capture information
                        2) have that information sent to an email address that is also pulled out of my database.

                        I just don't understand what this code is doing. Why the $_Request() - what is it requesting?

                        I set this up so long ago, that I did not remeber where I got it from - you are right, it is not from dreamweaver. Does dreamweaver have a better function?
                        • 9. Re: php email
                          Level 7
                          Dreamweaver does not have a built-in method for doing this.

                          Let me see your page containing the form, please.

                          > I just don't understand what this code is doing. Why the $_Request() -
                          > what
                          > is it requesting?

                          When a form is submitted to a script, the server loads several PHP variables
                          with the submitted data. One of these variables is called "$_REQUEST". The
                          script you showed is retrieving the email address from the form's submitted
                          data by referencing $_REQUEST['email']. That email address is coming
                          through in your emails as if the address is null, and since emails cannot be
                          sent with an empty "FROM" address, the server appears to be inserting the
                          default email address. I need to see the form to know what that field is
                          called and how it is identified to know if you are referencing it properly
                          with $_REQUEST['email'].


                          --
                          Murray --- ICQ 71997575
                          Adobe Community Expert
                          (If you *MUST* email me, don't LAUGH when you do so!)
                          ==================
                          http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                          http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                          ==================


                          "brywilson88" <webforumsuser@macromedia.com> wrote in message
                          news:gli6u6$7qc$1@forums.macromedia.com...
                          > What I am trying to do is:
                          >
                          > 1) capture information
                          > 2) have that information sent to an email address that is also pulled out
                          > of
                          > my database.
                          >
                          > I just don't understand what this code is doing. Why the $_Request() -
                          > what
                          > is it requesting?
                          >
                          > I set this up so long ago, that I did not remeber where I got it from -
                          > you
                          > are right, it is not from dreamweaver. Does dreamweaver have a better
                          > function?
                          >

                          • 10. Re: php email
                            brywilson88 Level 1
                            There is no email field to reference. How I have this set up. A user comes to the form. They imput some basic information. I then want that information sent to my email.

                            I have reduced the code to:

                            <?php

                            $my_email = "myemail@myemail.com";

                            function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

                            $message = build_message($_REQUEST);

                            $message = stripslashes($message);

                            $subject = "Information";

                            $headers = "From: My Company <customerservice@mycompany.com> \r\n";
                            $headers = "Return-Path: Returned <returned@mycompany.com> \r\n";
                            $headers = "Reply-To: My Company <customerservice@mycompany.com> \r\n";

                            mail($my_email,$subject,$message,$headers);

                            ?>

                            However, it seems none of the headers are working right.

                            I get the email in myemail@myemail.com

                            But, the From is “Doep76Fdep3tdn312.shr.phx4.secureserver.net” and it tries to reply here.

                            When I try to change some of the headers, I get errors for the line: mail($my_email,$subject,$message,$headers);

                            I set the headers like Chepe Nicoli stated above.

                            Just not sure what is wrong here. – Maybe I need to change something on the server where my email accounts are.
                            • 11. Re: php email
                              Level 7
                              Don't reduce the code as you have.

                              Change this -

                              $headers = "From: My Company <customerservice@mycompany.com> \r\n";
                              $headers = "Return-Path: Returned <returned@mycompany.com> \r\n";
                              $headers = "Reply-To: My Company <customerservice@mycompany.com> \r\n";

                              to this -

                              $headers = '';
                              $headers .= "From: My Company <customerservice@mycompany.com> \r\n";
                              $headers .= "Return-Path: Returned <returned@mycompany.com> \r\n";
                              $headers .= "Reply-To: My Company <customerservice@mycompany.com> \r\n";

                              and see what happens.

                              --
                              Murray --- ICQ 71997575
                              Adobe Community Expert
                              (If you *MUST* email me, don't LAUGH when you do so!)
                              ==================
                              http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                              http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                              ==================


                              "brywilson88" <webforumsuser@macromedia.com> wrote in message
                              news:gli9nn$b0g$1@forums.macromedia.com...
                              > There is no email field to reference. How I have this set up. A user
                              > comes to
                              > the form. They imput some basic information. I then want that
                              > information
                              > sent to my email.
                              >
                              > I have reduced the code to:
                              >
                              > <?php
                              >
                              > $my_email = "myemail@myemail.com";
                              >
                              > function
                              > build_message($request_input){if(!isset($message_output)){$message_output
                              > ="";}if(!is_array($request_input)){$message_output =
                              > $request_input;}else{foreach($request_input as $key =>
                              > $value){if(!empty($value)){if(!is_numeric($key)){$message_output .=
                              > str_replace("_"," ",ucfirst($key)).":
                              > ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .=
                              > build_message($value).", ";}}}}return rtrim($message_output,", ");}
                              >
                              > $message = build_message($_REQUEST);
                              >
                              > $message = stripslashes($message);
                              >
                              > $subject = "Information";
                              >
                              > $headers = "From: My Company <customerservice@mycompany.com> \r\n";
                              > $headers = "Return-Path: Returned <returned@mycompany.com> \r\n";
                              > $headers = "Reply-To: My Company <customerservice@mycompany.com> \r\n";
                              >
                              > mail($my_email,$subject,$message,$headers);
                              >
                              > ?>
                              >
                              > However, it seems none of the headers are working right.
                              >
                              > I get the email in myemail@myemail.com
                              >
                              > But, the From is ?Doep76Fdep3tdn312.shr.phx4.secureserver.net? and it
                              > tries to
                              > reply here.
                              >
                              > When I try to change some of the headers, I get errors for the line:
                              > mail($my_email,$subject,$message,$headers);
                              >
                              > I set the headers like Chepe Nicoli stated above.
                              >
                              > Just not sure what is wrong here. ? Maybe I need to change something on
                              > the
                              > server where my email accounts are.
                              >
                              >

                              • 12. Re: php email
                                brywilson88 Level 1
                                Sorry about the confunsion. I think I can clear this up.

                                On the From: line - I don't want the users email address or anything from the user. I want my name and email to be on the from line.

                                I also want to have any retunrs or replys sent to my name and email.

                                I hope this makes sense.

                                I have removed the $_REQUEST['email'] - can I just insert the emails that I want here?

                                Sorry for the confussion. I see that the confusion was on my side.
                                • 13. php email
                                  brywilson88 Level 1
                                  Murray - thanks. I got it figured out. I was just confused about the FROM line. Your questions help me better understand and then I just played with it until I got it to work.

                                  I did your suggestions without the \r\n - not sure why I need those - works without them.

                                  Thanks.
                                  • 14. Re: php email
                                    Level 7
                                    Good luck!

                                    --
                                    Murray --- ICQ 71997575
                                    Adobe Community Expert
                                    (If you *MUST* email me, don't LAUGH when you do so!)
                                    ==================
                                    http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                                    http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                                    ==================


                                    "brywilson88" <webforumsuser@macromedia.com> wrote in message
                                    news:glic1p$dpl$1@forums.macromedia.com...
                                    > Murray - thanks. I got it figured out. I was just confused about the
                                    > FROM line. Your questions help me better understand and then I just
                                    > played with it until I got it to work.
                                    >
                                    > Thanks.

                                    • 15. Re: php email
                                      brywilson88 Level 1
                                      This forum is the best - I learn so much.
                                      • 16. Re: php email
                                        Level 7
                                        Me too. 8)

                                        --
                                        Murray --- ICQ 71997575
                                        Adobe Community Expert
                                        (If you *MUST* email me, don't LAUGH when you do so!)
                                        ==================
                                        http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                                        http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                                        ==================


                                        "brywilson88" <webforumsuser@macromedia.com> wrote in message
                                        news:glid2p$evc$1@forums.macromedia.com...
                                        > This forum is the best - I learn so much.