SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question tricky php mail help

    Hi PHP-Expert,


    I would like to ask if you are able to help me.
    I would like to create a simple mail script using phpmail() or smtp(i have the smtp account).
    The requirement might be a bit complicated.

    Example my case :
    I have 50 clients and each of them are having different business sector.
    I would like to send them an email with unique email's content for each of the clients with just 1 time sending.
    let's say :
    1. Client = Microsoft.COM
    detail = a big company in USA
    email = mail@microsoft.com

    2. Client = CDNOW.COM
    detail = selling a lot of CDs
    email = mail@cdnow.com

    3. Client = Converse.com
    detail = one of the biggest shoe retailer
    email = sell@converse.com

    I would like to send to the 3 clients above but the content of the email is depend on the "detail" variable.

    example :

    Hi {Client},

    we know {Client} is {detail}.

    Each of the client will receive the email with different email's content.

    Anyone can help me?
    The email is in TEXT and the file which loaded should be separated by Standard CSV.

    The script should load the client detail's variable from excel or text file.

    I hope someone can help me

    thank guys

  2. #2
    SitePoint Evangelist speda1's Avatar
    Join Date
    Jan 2002
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can make an email template with your placeholders, load that into a buffer, then loop through the recipients and programmatically replace the placeholders with the recipient data, and then fire it off.

  3. #3
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wrote a snippet of code:
    Code:
    //get clients from csv file
    //Csv is like this:
    //client1name,client1detail,client1email
    //client2name,client2detail,client2email
    //client3name,client3detail,client3email
    $row = 1;
    $current_client_name=null;$current_client_detail=null;
    $current_client_email=null;
    $email_content=array("a big company in USA" => "text1", "selling a lot of CDs" => "text2","one of the biggest shoe retailer"=>"text3");
    $email_text=null;
    if (($handle = fopen("myclients.csv", "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            $num = count($data);
            echo "<p> $num fields in line $row: <br /></p>\n";
            $row++;//$data is an array with 3 elements
    		//$data[0] is Client name
    		//$data[1] is Client detail
    		//$data[2] is Client email address
            $current_client_name=$data[0];
    		$current_client_detail=$data[1];
    		$current_client_email=$data[2];	
    		$email_text="Hi ".$current_client_name."\n\nwe know ".$current_client_name." is ".$current_client_detail."\n".$email_content[$current_client_detail];
    		mail($current_client_email, 'My Subject', $email_text);
            }
        }
        fclose($handle);
    }
    All clients are loaded from a csv called myclients.csv . The text of your 3 emails is hard-coded in an associative array.
    You can also modify code to load the body of your email from text files.

    Hope this helps
    Antonio


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •