Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 394
  • Last Modified:

Can PHP mail() function be hacked to send mail to a single email address only?

We have a linux/apache/php development server with PHP applications calling sendmail. We disabled sendmail by making PHP point to /dev/null to avoid sending mail to actual customers. I would prefer to hack PHP so that any mail sent from PHP goes to a local email address. We need to examine it and not worry about it getting sent to the real address. Does anyone know of a way to do this? (I don't want to mess with sendmail because it's used by other functions on the box.
0
luxurylink
Asked:
luxurylink
  • 3
  • 3
  • 3
  • +3
1 Solution
 
davebytesCommented:
Ummm... To restate, you have a dev box on which you want to do experimental mail sending, but don't want the mails to actually go out.  And have sendmail being used for other uses.

Why don't you use a php mail library (phpMailer for one, or roll your own as a simple function!), and then have the library code change the TO address being passed through.  Using your own library is by far the easiest approach.

Other options would be to have a secondary SMTP daemon running on a different port, and maybe configure PHP to mail through that port?  Not sure if that's doable or not...

-d
0
 
PromethylCommented:
I believe if you do to a dev image of PHP you can override functions... migth just override mail().
0
 
Marcus BointonCommented:
I'd go with dave's suggestion. Just never use mail() directly. It would be very easy to patch phpMailer to pretend to send messages for development purposes, and it would also mean you wouldn't need to touch PHP configuration. Something I do is to have scripts that run differently according to which server they are on, so you can safely run development stuff without accidentally disabling it when you transfer updated code to your real server, along the lines of:

if($currentserver == 'dev')
  print 'yup, I really sent it, honest';
else
  $mail->send();
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
PromethylCommented:
"We disabled sendmail by making PHP point to /dev/null to avoid sending mail to actual customers."

I got the impression he was a webhost with runaway spamming users.

Why would you cut off your own email server?
0
 
davebytesCommented:
He can answer himself, but he says "development server".  Not 'hosting box'.  And pointing PHP to /dev/null meaning "we're writing some email code, but don't want test emails to actually go out to real customers".  Thus my suggestion of not using the mail() function but a third-party lib like a self-made, or phpMailer, type thing.

He doesn't WANT to cut off his own email, thus the note "I don't want to mess with sendmail".  So the only easy, simple, useful thing to do is replace mail() usage with a custom function.  Takes like 10 minutes to write or download a solution and have it working. ;)

-d
0
 
PromethylCommented:
Indeed. Good on you.
0
 
hujiCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: davabytes {http:#13731623}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Huji
EE Cleanup Volunteer
0
 
hujiCommented:
luxurylink,
You shouldn't accept the cleanup message. I'll ask an Admin to reopen the question, and then you will be able to accept the comment that "answered" your question.
Wish I can help
Huji
0
 
luxurylinkAuthor Commented:
Doh! Thanks but none of the answers were acceptable. (No offense guys.) I'd completely forgotten about this question, BTW.

In case you all are wondering, I simply replaced PHP's sendmail_path variable from /bin/sendmail to point to perl script that I wrote that pipes the email stream through sed and swapped out the actual recipient addresses with a local account. In this way we avoid sending PHP-generated emails to actual users and we can debug to our heart's content. Thanks again for your inputs.

0
 
davebytesCommented:
Umm, and I'd like to know why phpMailer (or other replacement of mail()) wasn't acceptable.  Sounds like you actually ended up going a much more complex route, though presumably any app developed using mail() goes through your filter.  Especially if you are developing we apps for deployment, use of mail() is generally discouraged, and many large projects have included phpMailer functions instead...

Ah well.
0
 
luxurylinkAuthor Commented:
Because I'm not a PHP guy and wanted to implement something external altogether. We didn't want to implement a slew of code changes (regardless of how simple) either.  Once I realized the solution, it took less than an hour to write a perl script that did exactly what I wanted. PHP remained untouched except for one line in php.ini
0
 
luxurylinkAuthor Commented:
Further to davebytes comment, I realize that my question itself says "hack PHP mail()" and I'm sorry for that. I changed my mind on the deisred approach after the early comments came in. I'll be more careful when posing questions in the future.
0
 
hujiCommented:
luxurylink,

You have the option to ask for deleting the question and refunding your points, in Community Support topic area. Read more here:
http://www.experts-exchange.com/help.jsp#hs5

Wish I can help
Huji
0
 
DarthModCommented:
PAQed with points (125) refunded

DarthMod
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now