Reputation: 19
So I am sending an HTML e-mail which is an invitation, and I would want users to click Join! if they would want to join the invitation, but then I have no idea how to retrieve their e-mail addresses. I can only get hits of how many "Yes"es I have got, I can't see which e-mail has actually said yes. How can I get their e-mail address too? beside providing them with a text field asking them to fill it up.
Any thoughts? thanks :)
My cade so far:
<html>
<body>
<form action="myserver.com" method="POST" target="_blank">
<input type="hidden" name="answer" value="yes"/>
<input type="submit" name="submit" value="Join!"/>
</form>
</body>
</html>
For the server side, I am using PHP to retrieve the data. Could anything be done from there? I can't use PHP or JS in my e-mails as far as I know.
Upvotes: 1
Views: 3765
Reputation: 12193
You would have to put their address in the href url as a parameter. It is the only way to get it back.
I won't bother putting all the PHP mail code in here but when you pass something like this:
$address = "[email protected]";
$msg = '... <a href="http://yoursite.com?email='.$address.'">click here</a> ...'
mail($address, $subject, $msg, $header);
It will render in the email like this:
<a href="http://[email protected]">click here</a>
When they click it, it will send the parameter to your webpage, where you can access it with $_GET['email']
Upvotes: 1
Reputation: 1781
Since you mention PHP, why not send the email programmatically?
Assuming you have a working SMTP configuration (see Local SMTP), all email adresses in an array, you could use PHP to send out the emails.
See the examples at the resources for specific headers needed for HTML
<?php
$email_addresses = array('[email protected]', '[email protected]');
// subject
$subject = 'Invitation';
// message
$message = '
<html>
<body>
<form action="myserver.com" method="POST" target="_blank">
<input type="hidden" name="answer" value="yes"/>
<input type="hidden" name="email" value="%placeholder%" />
<input type="submit" name="submit" value="Join!"/>
</form>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set - general part of the header
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Invitation <[email protected]>' . "\r\n";
// iterate over all email addresses
foreach ($email_addresses as $address)
{
// specific version of header
$header = $headers . 'To: ' . $address . ' . "\r\n";
// specific version of message
$msg = str_replace('%placeholder%', $address, $message);
// Mail it
mail($address, $subject, $msg, $header);
}
?>
As always, there are many ways to rome, so you could also input a link into the mail which has the email address (or some other sort of ID) as GET parameter.
Take special care with encodings (ISO vs UTF).
Also, your webserver will be the sender of the Email, so it might get caught in spamfilters if the address differs from the FROM field.
Getting PHP's mail() function to work can be a bit tricky, but the internet is full of solutions, so good luck!
Upvotes: 1