简体   繁体   中英

Current page url in subject line via mailto?

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>";?>

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>";?>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM