/    Sign up×
Community /Pin to ProfileBookmark

PHP Mail Interceptor

Hi guys

Here’s the scenario…

I’d like to intercept all unrouted mail and scan the contents for key phrases. If found then send a specific response, if not then send a standard response.

Here’s what I have thus far:

[code=php]
#! usr/local/bin/php -q
<?php
// Read From Stdin:
$data = ”;
$file = fopen(‘php://stdin’, ‘r’);
while(!feof($file))
{
$data .= fgets($file, 4096);

// Let’s Do Something:
$to = “[email protected]”;
$subject = “Test Mail From PHP Mail Interceptor”;
$message = “Hello! This is a simple email message from your mail interceptor.”;
$from = “[email protected]”;
$headers = “From:” . $from;
mail($to,$subject,$message,$headers);
}
fclose($file);
?>
[/code]

Now it works, kind of. It sends 25 messages so I can only assume it’s sending one message for each line of the file it opens.

Here’s what I would “like” to do…

[code=php]
#! usr/local/bin/php -q
<?php
// Read From Stdin:
$data = ”;
$file = fopen(‘php://stdin’, ‘r’);
while(!feof($file))
{
// Define a string to look for here. “Chicken Wings Special” for example

// Search here for “$SearchString” using stristr perhaps…?

// Now run an if statement and send a mail “IF” $SearchString is found

$data .= fgets($file, 4096);

// Let’s Do Something:
$to = “[email protected]”; <– Inject the sender’s mail address here
$subject = “Test Mail From PHP Mail Interceptor”; <– This I can customise based on the $SearchString
$message = “Hello! This is a simple email message from your mail interceptor.”;
$from = “[email protected]”;
$headers = “From:” . $from;
mail($to,$subject,$message,$headers);
}
fclose($file);
?>
[/code]

I tried and inserted an if statement following stristr but the mail failed.

Any suggestions…?

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @Harlequin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...