0

How to populate current page title (or current url) to the subject line via mailto?

Been using the code below as a starting point, obviously modifying the "Page Title Here" bit, but can't find a solution:

<?php echo "<a href='mailto:test@test.com" . $to . "?subject=Page Title Here" . $subject . "'>Send an email</a>";?>
  • the page title is the title you gave it in your script. So go back up in your script, and copy it. PHP does not parse your already output HTML, and as such has not the slightest clue what the title might be. It doesn't even know the concept of a page title. – Tularis Mar 27 '14 at 21:08
  • http://stackoverflow.com/questions/12592410/get-page-title-url-and-echo-in-html – Malcolm Mar 27 '14 at 21:09

2 Answers2

1

Set page title to php var as

$title = 'Example';

and use it for

<title><?=$title;?></title>

and mail

 <?php echo "<a href='mailto:test@test.com" . $to . "?subject=" . $title . $subject . "'>Send an email</a>";?>
Itsmeromka
  • 3,621
  • 9
  • 46
  • 79
0

This is not generically possible with PHP. PHP has no knowledge of what the page title is, or your HTML structure at all.

You will have to go to your code where you set the page title, and use that same variable in your e-mail. If this PHP code is handling a post from some page or something, you need that page title posted with your form data (which you can get with JavaScript document.title).

Brad
  • 159,648
  • 54
  • 349
  • 530