Jump to content

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


Jegs

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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.