Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8458721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:09:21+00:00 2026-06-10T13:09:21+00:00

I am piping email that get’s sent to my server to a PHP script.

  • 0

I am piping email that get’s sent to my server to a PHP script. The script parses the email so I can assign variables.

My problem is once in awhile somebody will include my email address to an email that’s getting sent to multiple recipients and my script will only get the first one. I need it to find my email address then assign it to a variable.

Here is what the email array looks like: http://pastebin.com/0gdQsBYd

Using the example above I would need to get the 4th recipient: my_user_email@mydomain.com

Here is the code I am using to get the “To -> name” and “To -> address”

# Get the name and email of the recipient
$toName = $results['To'][0]['name'];
$toEmail = $results['To'][0]['address'];

I assume I need to do a foreach($results['To'] as $to) then a preg_match but I am not good with regular expressions to find the email I want.

Some help is appreciated. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:09:22+00:00Added an answer on June 10, 2026 at 1:09 pm

    Instead of usin preg_match inside foreach loop you can use strstr like below

    Supposing you are looking for my_user_email@mydomain.com use following code

    foreach($results['To'] as $to)
    {
    
    // gets value occuring before the @, if you change the 3 rd parameter to false returns domain name
    
    $user = strstr($to, '@', true) ;
    if($user == 'my_user_email')
    {
    //your action code goes here
    }
    
    } 
    

    example:

    <?php
    $email  = 'name@example.com';
    $domain = strstr($email, '@');
    echo $domain; // prints @example.com
    
    $user = strstr($email, '@', true); // As of PHP 5.3.0
    echo $user; // prints name
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to program a email piping php script that would take an
I've got a PHP script that my mail server is piping emails to via
I'm doing this piping php script that fetch the arriving emails and the parse
I'm working on an email piping script that needs to save just the reply
I am using Get-WmiObject Win32_service and piping the output to CSV. My script is
Is piping parameter into line is working only for functions that accept one parameter?
I am having trouble piping through sed. Once I have piped output to sed,
I am trying to implement a linux shell that supports piping. I have already
I'm running a program that does piping. The command I want to run is
I have a simple script written to process received email. Here are the tested

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.