views:

41

answers:

3

I know it is possible to send html enabled emails. Is it also possible to send PHP enabled emails?

For this to count:

  • php code has to be sent as plain text
  • php code has to be executed on some server X only after recipient opens the email
  • Server X is not the recipient's machine

If this is possible, what are the consequential security issues that this brings up?

A: 

This cannot be done in the way I think you are thinking. You cannot send PHP code and expect it to be interpreted by the email client.

However, you can link to an image, on your server, in the HTML email. And this image could be a PHP script which runs on your server. But most email clients do not display images by default for this very reason.

w3d
he is not trying to have the php code executed by the client, but by a remote server
Palantir
@Palantir - well, this is what I would expect, but why does he state: "send PHP enabled emails" and "php code has to be sent as plain text"?
w3d
+1  A: 

I think your best bet is sending HTML with an iFrame or you can try an Ajax call to get the HTML you want to inject (using javascript). I don't think you can just send PHP code embedded in the HTML.

Check example #4 http://php.net/manual/en/function.mail.php

Dan Williams
+2  A: 

You are basically trying to force the remote email client to display a remote HTML page (generated by PHP). No clients will do that, because it's a big security risk.

You could use AJAX, but all modern email clients will completely block any Javascript in the emails by default.

You can however request remote images. You could generate them on the fly (handle the jpg extension by PHP and generate the image on the fly), but that's very likely to kill your emails as spam by any spam filter. Most email clients will block remote images by default, but will usually show a button to unblock them (this does not happen for javascript scripts).

Palantir