Re: Files
| From: | Bob Winter | Date: | Tue, 28 Jun 2005 12:26:45 +0000 |
| Subject: | Re: Files | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-217752@lists.php.net to get a copy of this message | ||
Chris,
He's my take on your problem, I have used a few different functions but followed the same pattern as your original script. Check out http://www.php.net/manual/en/ to get the details on the ones you don't understand. I have not included error checking. This example works successfully on my system.
--Bob
<?php
$recp_list = file("mail_group_list.txt");
$group_list = file("file_group_list.txt");
$cnt = 0;
foreach($recp_list as $line) {
$split = explode(',', $line);
$id = trim($split[0]);
$email = trim($split[1]);
if($email != '') {
foreach($group_list as $groupline) {
$groupsplit = explode(",", $groupline);
$groupid = trim($groupsplit[0]);
$groupFileName = trim($groupsplit[1]);
if($id == $groupid) {
$cnt++;
// start mailing
$fromname = "Test Mailer";
$fromaddress = "email@email.com";
$subject = "Test mail";
$message = "Test message $groupFileName";
$headers = "From: $fromname <$fromaddress>\n";
// Notify the user on screen if the send was succesfull
if(mail($email, $subject, $message, $headers)) {
print "Mail sent successfully to $email";
} else {
print "Mail not sent to $email";
}
}
}
}
}
if(!$cnt) {
print 'No matches in files.';
}
?>
Chris Grigor wrote:
Hey all, I am having a bash at working with flat files. What I am trying to achieve is the following There are 2 files with info in them, file1 has id,email and file2 has id,filename what I am trying to achieve is open up file1 get the id and email then open file2 and match the id of file1 to id of file2, then if succesful send a mail with the filename in file2. Maybe have a look at the code... $recp_list = fopen("mail_group_list.txt", "r"); while(!feof($recp_list)) { $line = fgets($recp_list, 255);$line = chop($line);$split = explode(",", $line); $id = $split[0]; $email = $split[1]; // time to mail.if ($email != "") {$group_list = fopen("file_group_list.txt", "r"); while(!feof($group_list)) { $groupline = fgets($group_list, 255); $groupline = chop($groupline); $groupsplit = explode(",", $groupline); $groupid = $groupsplit[0]; $groupFileName = $groupsplit[1]; if($groupid = $id) { // start mailing $fromname = "Test Mailer"; $fromaddress = "email@email.com"; $subject = "Test mail"; $message = "Test message $groupFileName"; $headers = "From: \"".$fromname."\" <".$fromaddress.">\n"; // Notify the user on screen if the send was succesfull if(mail($email, $subject, $message, $headers)) { print "Mail sent successfully to $email"; } else { print "Mail not sent to $email"; } }#end if groupid = id }#end while group list }#end if email }#end while email !="" ?> So thats the mail.php mail_list_group.txt looks like this 1,test@test.com 5,test1@test.com 7,test@test.com file_group_list.txt looks like this 2,filename1.doc 3,filename2.doc 4,filename3.doc Any help on this would be great ! Cheers Chris PS the formatting might come out all wrong as its mailed from a web account.