0

I would like to include Gravatar profile pictures in the newsletter that I am sending. I know that I can't just add a URL to the Gravatar-service with a URL as parameter but need to do some hashing first.

I do have a PHP enabled web site that I could use to "translate" the email to MD5 hash and perhaps return the complete image URL to be used in the newsletter, but I don't know how.

If I do it like this, then all I get is printed the URL on the webpage :

$email = "someone@somewhere.com";
$default = "http://www.mywebsite.com/homestar.jpg";
$size = 40;
$grav_url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;
echo $grav_url;

How can I "return" the complete URL so that I in the newsletter can write something like:

<img src="http://www.mywebsite.com/my-php-script.php?email=someemail@domain.com">`

(BTW I will of course dynamically insert the email like this in the newsletter:

http://www.mywebsite.dk/my-php-script.php?=[DYNAMICFIELD_EMAIL]` )

Perhaps some redirect of sorts?

Or if this will not work, can I instead have the script return the actual image?

Tim
  • 41,901
  • 18
  • 127
  • 145
  • What doesn't work with your example? The way you wrote it it should work for `` – Veve Dec 18 '15 at 10:22
  • 1
    Possible duplicate of [How to build a url of a GRAVATAR image from a given email](http://stackoverflow.com/questions/2718860/how-to-build-a-url-of-a-gravatar-image-from-a-given-email) – Veve Dec 18 '15 at 10:23
  • @Veve: Yes, I am not going to use it in a PHP script but "externally", - in a newsletter. So need the "next step" compared to the other question - I have sorted how to build the URL, but need help on how to use it outside PHP.. So not a dublicate! :-) – Christian Dec 18 '15 at 10:48

1 Answers1

0

Your code would require to return the actual image because it is used in the src attribute of img. Can you have a [DYNAMICFIELD_EMAIL_HASHED] - would make things much easier.

Otherwise you could look at fpassthru. With that you can download and output the gravatar image directly and your newsletter code would work. But I am not sure if this violates Gravater terms of usage. Also you will have to do some error handling, maybe caching, change of headers, etc.

ZoolWay
  • 5,411
  • 6
  • 42
  • 76
  • Thank you! Yes, something like [DYNAMICFIELD_EMAIL_HASHED] would be great - but because this list is highly dynamic (and partly because I can't find time to generate and upload all hashed emails before every sending) that is not possible. Thanks, fpassthru looks complicated - I will try to find some examples that might make it understandable for an amateur like me. :) – Christian Dec 18 '15 at 10:53