Jump to content

Archived

This topic is now archived and is closed to further replies.

Jegs

Multiple addresses for only one Display name, Can be done?

Recommended Posts

Hi guys

I'm new here! so sorry if this is off topic. I search teh forum if this thread was previously treated, but I didn't find anything.

The question is very simple. I'm sending mails throught php with the mail function, and using a plain text file to store the addresses that users have suscribed.

The text file has a simple format just like:

User1 <user1@domain.com>, User2 <user2@domain.com>

The php, reads the text file and associates it whole content to a variable called $to used to send the mail after. The previous formats works ok, but:

If for example a user wants to register two addresses how should I format it in the text file. I have tried this:

User3 <user3_address1@domain.com, user3_address2@domain.com>

but It doesn't work. Anyone could help please :D


Best regards
Javier

Share this post


Link to post
Share on other sites
How you format it is really all up to you. It depends on how you're going to parse the file to get the information out.

You might want to look into the parse_ini_file() function (http://www.php.net/parse_ini_file), which will take a file in a particular format and return the information in an array.

In your case, if you change the format of your file to:
[code]
[user1]
email[] = user1@example.com

[user2]
email[] = user2@example.com

[user3]
email[] = user3a@example.com
email[] = user3b@example.com
[/code]

The results of using code something like this:
[code]<?php
$user_email = parse_ini_file('user_email.txt',true);
echo '<pre>' . print_r($user_email,true) . '</pre>';
?>[/code]
Is an array containing:
[code]
Array
(
    [user1] => Array
        (
            [email] => Array
                (
                    [0] => user1@example.com
                )

        )

    [user2] => Array
        (
            [email] => Array
                (
                    [0] => user2@example.com
                )

        )

    [user3] => Array
        (
            [email] => Array
                (
                    [0] => user3a@example.com
                    [1] => user3b@example.com
                )

        )

)
[/code]

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.