开发者

How to add custom subject/header to mail() only called from within a specific folder

I have a PHP script that is uploaded to a /fol开发者_开发百科der

It has several pages where uses the mail() function of PHP. I would like to alter the subject eg: [folder] when the mail() function is called from the script that resides in the /folder.

How can I do that?


You can find what folder the current script is in with __DIR__ magic constant
http://www.php.net/manual/en/language.constants.predefined.php

If you use some standard library to send emails, your script might look similar to this.

$folder = end(explode(DIRECTORY_SEPARATOR, __DIR__));
// or dirname(__FILE__) instead of __DIR_ for PHP 5.2

$mail = new Mail();
$mail->addTo('email@example.com')
     ->subject('['.$folder.'] subject')
     ->send();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜