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).
Related
I have a google map on this page, all markers were generated by submit postcodes. So I have the array below, loop info of each marker,
imploded as ("array", "array") format, I am trying to click on a infoWindow and display the according marker details on details.php.
The problem is everything is on the button onclick event, only a simple get on the second page.
This is working, but it is a very bad way. Because the limit to URL length and security reasons;
I would like to be able to get an array info from details.php page,
and the button onclick event trigger url looks like: details.php?marker=id
I don't know what is the best way to go about this, can someone pointing me to the right direction please?
index.php
$info = array();
foreach($stmt as $x)
{
$info[] =
"<h4>" . $x['name'] . "</h4><hr />".
"<h5>Address: </h5>" . $x['Address']."<br />" .
"<h5>Postcode: " . $x['postcode'] ."</h5><br />" .
"<button onclick='window.location.href= \\\"details.php?marker=". "<h4>" . $x['name'] . "</h4><hr />".
"<h5>Address: </h5>" . $x['address']."<br />" . "<h5>Postcode: " . $x['postcode'] ."</h5><br />" . "\\\" ' >
View Details</button>";
}
$i=' "'.implode('","', $info).'"';
details.php
echo $infomarker = $_GET['marker'];
You have to use $x['id'] insted of $x['name'] which is unique in your database and also use base64_encode() for encryption of your id "details.php?marker=".base64_encode($x['id'])."
In your details.php
$infomarker = base64_decode($_GET['marker']);
Try using AJAX to get the info from details.php and then load it into your InfoWindow.
I didn't realise how simple this was, all I need is use that id, write it inside a sql statement in details page then call any part of the statement out. Thanks everyone. Thanks to #Manjeet Barnala for encode tips.
I can't seem to get this to work...what I have is a link being auto-generated to send out in an email, and I need to be able to append the user's email address to the URL, but I can't seem to get it formatted correctly. Here's what I have:
href=\"http://example.com/unsubscribe/\" . $email . \"\"
Where the resulting link in the user's email should be
http://example.com/unsubscribe/myemail#myemail.com
The way the unsubscribe is structured, it wants it the above format instead of with ?email=. Can I do this?
EDIT 12/3/13:
Thanks for all the help, guys! Part of my problem is that I wasn't passing the email var through my generate email function. :/
Here's how I ended up setting it up:
$unsubscribeurl = 'http://example.com/unsubscribe/';
$unsubplus = $unsubscribeurl . $email;
$unsubscribelink = 'UNSUBSCRIBE';
Then to set the link up, I just used $unsubscribelink.
Creating the url:
$url = 'http://example.com/unsubscribe/' . urlencode($email);
Creating the link:
$link = 'link';
Using the link in html context:
<?php echo $link ?>
Or:
link
urlencode()
htmlspecialchars()
I want to get values of clicked links in the final page.
e.g. Computer & Network/Components and parts -- New York /City
Example.
Page1
$Category = $_POST["cat"];
$Subcategory =$_POST["Subcat"]
Page 2
$Province = $_POST["Province"];
$City =$_POST["City"]
{echo "You selected to post on"$Category . "Subcategory" In $Province . $City}
I want to use links not submit button to display selected links
USE $_GET
for example :
link
PHP:
echo "You selected to post on" . $_GET["cat"] . "/" . $_GET["subcat"] . " - " . $_GET["province"] . "/" . $_GET["city"];
Normally, this sort of thing is accomplished with $_GET variables, rather than $_POST variables. These go after the document name in the URL. Like so:
site.com/myPage.php?cat=Category&subcat=Subcategory
If you absolutely need POST (for reasons I'm not sure I'd understand) you may be able to use a Javascript framework like JQuery to make invisible forms that post when you click a link. Just realize this is going to make navigation hell...each time someone clicks 'Back', the browser will warn them they may be resubmitting information.
The easiest way would be to use COOKIES.
But I recommend using the get method to pass them via url, and that is described in the other answers here.
Example
Page1
$Category = $_POST["cat"];
$Subcategory =$_POST["Subcat"];
$_COOKIE["cat"] = $Category;
$_COOKIE["Subcat"] = $Subcategory;
Page 2
$Category = $_COOKIE["cat"];
$Subcategory =$_COOKIE["Subcat"];
$Province = $_POST["Province"];
$City =$_POST["City"];
echo "You selected to post on".$Category . "Subcategory In". $Province . $City;
I hope I'm missing something pretty basic here but: An empty form is getting submitted randomly, sometimes 3-8 times a day, then none for a few days and so on.
The empty submits always email with the subject as "[Website Contact Form]." Even though there is no validation in my php, in the html code the subject is chosen from a drop-down menu with the default as "General Enquiry." Notice in the php code below, there is no way for a human to submit an empty form with the above subject line, that is, it would always be "[Website Contact Form]General Enquiry" if I press submit without entering anything.
I have contact.html call this contact.php file:
<?
$email = 'info#mail.com';
$mailadd = $_POST['email'];
$headers = 'From: ' . $_POST['email'] . "\r\n";
$name = $_POST['name'];
$subject = '[Website Contact Form] ' . $_POST['subject'];
$message = 'Message sent from: ' . $name . '. Email: ' . $mailadd . '. Organization: ' . $_POST['company'] . '. Phone: ' . $_POST['phone'] . '. ';
$message .= 'Message: ';
$message .= $_POST['message'];
if (mail($email,$subject,$message, $headers)) {
echo "<p>Thank You! We'll get back to you shortly.</p>";
}
else {
echo "<p>Error...</p>";
}
?>
I use this code for many websites, but have never encountered this issue. Is there something so obviously wrong with this code that I'm missing? Any help would be greatly appreciated!
I suspect that you may not be checking that these variables are set before you send the email. Someone requesting contact.php directly (without any form data) may produce the results you have described. If this is the case, the following code should work like a charm:
<?php
if (isset($_POST['submit']) {
// form code
}
else {
// The form was not submitted, do nothing
}
?>
Even if that's not that case, such a simple check is always good practice.
Furthermore, you should always validate any user input just as a good habit. You don't want your server flooding your inbox with emails. I suggest using regexs to validate the input provided and possibly use a captcha service (such as ReCaptcha).
If you've been using this code and it's been working fine then I'd check what variables you changed with this case for example your submit form.
Try out your form with all common possibilities and see if it works. And empty Subject will give your form the subject "[Website Contact Form]". Check that your script actually get's the post variables and your form submits the right variables. Your dropdown might have an option with value of "" and the innerHTML "General Enquiry". The value is what will get submitted.
It's good to check inputs server-side as well
<?php
if(isset($_POST['subject'],$_POST['email'])){
}
?>
I have a PHP script that emails me the results from a form that generates a unique ID number. The PHP script executes a confirmation page. I'm trying to place the unique ID on the confirmation page: quote_confirm.php. I already tried this in the conformation page:
<?php
$prefix = 'LPFQ';
$uniqid = $prefix . uniqid();
$QuoteID = strtoupper($uniqid);
."<tr><td class=\"label\"><strong>Quote ID:</strong></td><td>".$QuoteID."</td></tr>\n"
First off, uniqid() has a prefix parameter, so your line $uniqid = $prefix . uniqid(); should actually be $uniqid = uniqid($prefix);
Also, are you receiving an error? What is the output?
From what I can understand it is something like this:
form -> mail + output page
So there is mail()-like function and after that some output.
If the variable($uniqid) is set you have to make sure it's not overwritten or unset by something else before the actual output. You have to also check the scope of variable.
There is no mistake in the code you posted.
But speaking of style:
I also recommend using using $uniqid = uniqid($prefix) instead of $uniqid = $prefix. uniqid();.
And the following line is strange:
."<tr><td class=\"label\"><strong>Quote ID:</strong></td><td>".$QuoteID."</td></tr>\n"
Write it as "<tr><td class=\"label\"><strong>Quote ID:</strong></td><td>$QuoteID</td></tr>\n" (if you insist on using "") and if the function is echo (example: echo $something not $content .= $something) use , instead of . .
Full example:
echo 'Constant text without variables', $variable, "String with a $variable and a newline \n";