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 :
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.
//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>\
";
$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."\
\
we know ".$current_client_name." is ".$current_client_detail."\
".$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.