Connecting Tech Pros Worldwide Help | Site Map

URL and Page title in PHP

Member
 
Join Date: Aug 2006
Posts: 110
#1: Feb 19 '09
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:

Expand|Select|Wrap|Line Numbers
  1. <form action="emailus.php" method="POST" name="Email_Submit" class="divtext"> 
  2.  
  3.                                                 <table width="400" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111">
  4.                           <tr>
  5.                             <td width="47%" valign="top">First Name:</td>
  6.                             <td width="53%" valign="top">
  7.                             <input name="FirstName" type="text" id="Contact_FName" size="20"></td>
  8.                           </tr>
  9.                           <tr>
  10.                             <td valign="top">Last Name: </div></td>
  11.                             <td valign="top">
  12.                             <input name="LastName" type="text" id="Contact_LName" size="20"></td>
  13.                           </tr>
  14.                           <tr>
  15.                             <td valign="top">Your E-mail:</td>
  16.                             <td valign="top">
  17.                             <input name="Email" type="text" id="Contact_Email" size="20"></td>
  18.                           </tr>
  19.                           <tr>
  20.                             <td valign="top">Your Question:</td>
  21.                             <td valign="top">
  22.                             <textarea name="Question" rows="5" id="Question" cols="20"></textarea></td>
  23.                           </tr>
  24.                               <tr>
  25.                             <td valign="top"><input name="Submit" type="submit" value="Submit"></td></tr>
  26.  
  27.            </form>
  28.  
Here is the emailus.php code:

Expand|Select|Wrap|Line Numbers
  1. <?
  2.   $FirstName = $_POST['FirstName'];
  3.   $LastName = $_POST['LastName'];
  4.   $email = $_POST['Email'];
  5.   $question = $_POST['Question'];
  6.  
  7. $message="First Name: $FirstName \n
  8.   Last Name: $LastName \n
  9.   Email: $email \n
  10.   Your Question: $question \n ";
  11.  
  12.   mail( "deepaks85@gmail.com", "Email Us Form Submission from", "Message: $message",  "From: $email" );
  13.   header( "Location: http://www.mydomain.com/thanks.html");
  14. ?>
  15.  
I will appreciate if anyone can help me on this...

Thanks

Deepak
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,094
#2: Feb 19 '09

re: URL and Page title in PHP


Quote:

Originally Posted by deepaks85 View Post

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:

Expand|Select|Wrap|Line Numbers
  1. <form action="emailus.php" method="POST" name="Email_Submit" class="divtext"> 
  2.  
  3.                                                 <table width="400" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111">
  4.                           <tr>
  5.                             <td width="47%" valign="top">First Name:</td>
  6.                             <td width="53%" valign="top">
  7.                             <input name="FirstName" type="text" id="Contact_FName" size="20"></td>
  8.                           </tr>
  9.                           <tr>
  10.                             <td valign="top">Last Name: </div></td>
  11.                             <td valign="top">
  12.                             <input name="LastName" type="text" id="Contact_LName" size="20"></td>
  13.                           </tr>
  14.                           <tr>
  15.                             <td valign="top">Your E-mail:</td>
  16.                             <td valign="top">
  17.                             <input name="Email" type="text" id="Contact_Email" size="20"></td>
  18.                           </tr>
  19.                           <tr>
  20.                             <td valign="top">Your Question:</td>
  21.                             <td valign="top">
  22.                             <textarea name="Question" rows="5" id="Question" cols="20"></textarea></td>
  23.                           </tr>
  24.                               <tr>
  25.                             <td valign="top"><input name="Submit" type="submit" value="Submit"></td></tr>
  26.  
  27.            </form>
  28.  
Here is the emailus.php code:

Expand|Select|Wrap|Line Numbers
  1. <?
  2.   $FirstName = $_POST['FirstName'];
  3.   $LastName = $_POST['LastName'];
  4.   $email = $_POST['Email'];
  5.   $question = $_POST['Question'];
  6.  
  7. $message="First Name: $FirstName \n
  8.   Last Name: $LastName \n
  9.   Email: $email \n
  10.   Your Question: $question \n ";
  11.  
  12.   mail( "deepaks85@gmail.com", "Email Us Form Submission from", "Message: $message",  "From: $email" );
  13.   header( "Location: http://www.mydomain.com/thanks.html");
  14. ?>
  15.  
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:


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.   $question = $_POST['Question'];
  4.    $question .= "\nThis could be the page title\n"; 
  5.    $question .= "URL: mysite.com/link/to/your/page"; 
  6.  
  7.  
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
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#3: Feb 19 '09

re: URL and Page title in PHP


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.
Familiar Sight
 
Join Date: Feb 2007
Posts: 135
#4: Feb 20 '09

re: URL and Page title in PHP


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.
Reply