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

  • SEARCH
  • Home
  • 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 7955675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:46:04+00:00 2026-06-04T03:46:04+00:00

I would like to let my users paste a string of emails into a

  • 0

I would like to let my users paste a string of emails into a text are and on submit import them into a db table.

It seem that the typical syntax for email and they way it is usually typed in TO field is:

"Fname Lname" <abc@email.com>, "Fname Lname" <abc@gmail.com>,

I suppose on submit I need to parse it through some loop. How do I detect the name/email pair break? Is there a way to also do some basic email validation?


UPDATE:

I realized that sometimes the string can be slightly off, like missing a name:

Fname Lname" <abc@email.com>, abc@gmail.com,

or even

<abc@email.com>, abc@gmail.com,

or even

abc@email.com, abc@gmail.com,

How to make it more robust and note break if a name is missing? The email should be there all the time! Otherwise it just needs to ignore an instance and move on to the next contact. But I guess I can do that validation after the array of contacts is created…

  • 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-04T03:46:06+00:00Added an answer on June 4, 2026 at 3:46 am

    I am not good in preg_match, so I tried it in another way. If your string is always in this pattern, you can try something like this:

    $str = '"Fname Lname" <abc@email.com>, "Fname Lname" <xyz@gmail.com>';
    
    $pairs = explode( ",", $str );
    
    foreach( $pairs as $pair ) {
    
      $pair = explode( "<", $pair );
      $pair['0'] = trim( str_replace( "\"", "", $pair['0'] ) );
      $pair['1'] = trim( rtrim( $pair['1'], ">" ) );
    
      print_r( $pair ); // Save it to database here
    }
    

    Test Here

    EDIT:

    (Change in input string)

    $str = '"Fname Lname" <abc@email.com>, abc@gmail.com';
    
    $pairs = explode( ",", $str );
    
    foreach( $pairs as $pair ) {
    
      if( strpos($pair, '<') ) {
    
        $output = explode( "<", $pair );
        $output['0'] = trim( str_replace( "\"", "", $output['0'] ) );
        $output['1'] = trim( rtrim( $output['1'], ">" ) );
    
      } else {
    
        $output = array();
        $output['0'] = '';
        $output['1'] = $pair;
    
      }
    
      print_r($output); // Save it to database here
    }
    

    Test Here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an application in which I would like to let the users
We let users create ad-hoc queries in our website. We would like to have
I would like to implement a basic versioning system in a MySQL table. Let's
I would like to let users resize my form but when they reach a
I would like to let Zend_Layout include header.phtml and footer.phtml with [layouy name].phtml. How
I would like to know how a listener should let the parent thread know
Let say I would like to set nested style for development and compressed for
I would like to store only .txt filenames from a specific dir (let's say:
I would like to bring up the Camera in my app, and let the
Let's suppose I'm using the Northwind database and I would like to run a

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.