SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2009
    0 Post(s)
    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 =

    2. Client = CDNOW.COM
    detail = selling a lot of CDs
    email =

    3. Client =
    detail = one of the biggest shoe retailer
    email =

    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
    0 Post(s)
    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
    0 Post(s)
    0 Thread(s)
    I wrote a snippet of code:
    //get clients from csv file
    //Csv is like this:
    $row = 1;
    $email_content=array("a big company in USA" => "text1", "selling a lot of CDs" => "text2","one of the biggest shoe retailer"=>"text3");
    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
    		$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);
    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

Tags for this Thread


Posting Permissions

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