URL and Page title in PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepaks85
    New Member
    • Aug 2006
    • 114

    #1

    URL and Page title in PHP

    Hi Friends,

    I have a simple HTML form and simple PHP code which sends the filled information at my email address. Now, I am trying to get Page URL and Page Title at my email while submitting a form alongwith the info filled by user.

    Here is my HTML form:

    Code:
    <form action="emailus.php" method="POST" name="Email_Submit" class="divtext"> 
    
                                                    <table width="400" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111">
                              <tr>
                                <td width="47%" valign="top">First Name:</td>
                                <td width="53%" valign="top">
                                <input name="FirstName" type="text" id="Contact_FName" size="20"></td>
                              </tr>
                              <tr>
                                <td valign="top">Last Name: </div></td>
                                <td valign="top">
                                <input name="LastName" type="text" id="Contact_LName" size="20"></td>
                              </tr>
                              <tr>
                                <td valign="top">Your E-mail:</td>
                                <td valign="top">
                                <input name="Email" type="text" id="Contact_Email" size="20"></td>
                              </tr>
                              <tr>
                                <td valign="top">Your Question:</td>
                                <td valign="top">
                                <textarea name="Question" rows="5" id="Question" cols="20"></textarea></td>
                              </tr>
                                  <tr>
                                <td valign="top"><input name="Submit" type="submit" value="Submit"></td></tr>
                            
               </form>
    Here is the emailus.php code:

    Code:
    <?
      $FirstName = $_POST['FirstName'];
      $LastName = $_POST['LastName'];
      $email = $_POST['Email'];
      $question = $_POST['Question'];
    
    $message="First Name: $FirstName \n
      Last Name: $LastName \n
      Email: $email \n
      Your Question: $question \n ";
    
      mail( "deepaks85@gmail.com", "Email Us Form Submission from", "Message: $message",  "From: $email" );
      header( "Location: http://www.mydomain.com/thanks.html");
    ?>
    I will appreciate if anyone can help me on this...

    Thanks

    Deepak
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Originally posted by deepaks85
    Hi Friends,

    I have a simple HTML form and simple PHP code which sends the filled information at my email address. Now, I am trying to get Page URL and Page Title at my email while submitting a form alongwith the info filled by user.

    Here is my HTML form:

    Code:
    <form action="emailus.php" method="POST" name="Email_Submit" class="divtext"> 
    
                                                    <table width="400" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111">
                              <tr>
                                <td width="47%" valign="top">First Name:</td>
                                <td width="53%" valign="top">
                                <input name="FirstName" type="text" id="Contact_FName" size="20"></td>
                              </tr>
                              <tr>
                                <td valign="top">Last Name: </div></td>
                                <td valign="top">
                                <input name="LastName" type="text" id="Contact_LName" size="20"></td>
                              </tr>
                              <tr>
                                <td valign="top">Your E-mail:</td>
                                <td valign="top">
                                <input name="Email" type="text" id="Contact_Email" size="20"></td>
                              </tr>
                              <tr>
                                <td valign="top">Your Question:</td>
                                <td valign="top">
                                <textarea name="Question" rows="5" id="Question" cols="20"></textarea></td>
                              </tr>
                                  <tr>
                                <td valign="top"><input name="Submit" type="submit" value="Submit"></td></tr>
                            
               </form>
    Here is the emailus.php code:

    Code:
    <?
      $FirstName = $_POST['FirstName'];
      $LastName = $_POST['LastName'];
      $email = $_POST['Email'];
      $question = $_POST['Question'];
    
    $message="First Name: $FirstName \n
      Last Name: $LastName \n
      Email: $email \n
      Your Question: $question \n ";
    
      mail( "deepaks85@gmail.com", "Email Us Form Submission from", "Message: $message",  "From: $email" );
      header( "Location: http://www.mydomain.com/thanks.html");
    ?>
    I will appreciate if anyone can help me on this...

    Thanks

    Deepak
    Maybe i'm not sure what your asking but you can always tack on more info to where the question is for example:


    Code:
    
      $question = $_POST['Question'];
       $question .= "\nThis could be the page title\n"; 
       $question .= "URL: mysite.com/link/to/your/page";
    Is that what your asking for?

    Check out $_SERVER[] on php.net to get all sorts of info on the server and file/page.


    Cheers,






    Dan

    Comment

    • TheServant
      Recognized Expert Top Contributor
      • Feb 2008
      • 1168

      #3
      As has already been said, you will need to pass the page title and address as variables in your form. I have a similar code where my title is a variable and on the page is normally echo'd as <title>...</title> but can also be sent as a variable through a hidden input in a form. To get the page url you will need the $_SERVER[] array as Dan said.

      Comment

      • devsusen
        New Member
        • Feb 2007
        • 136

        #4
        For the address/URL u can use $_SERVER variables, but for the title u need to pass it in a variable along with the form. Using javascript : document.title property u can fetch the title of the page and put it in a variable within the form.

        Comment

        Working...