Hello All,
I'm creating text files on the fly when a user submits some data through a form. Basically these files are stored in a sub dir with a random name, and I've got an email script which then notifies a recipient where this text file is and what its filename is.
What I'd really like to do, however, is send the actual text file when it's created, as an attachment, to this email address.
Below is the code I have to create the file & send the notification email. I'd like to know how to adapt it to attach the text file (i already have a function to create the random name). If anybody can help me out I'd be really grateful.
Thanks, Entropy.
// now write to file
if(strlen($csvLine) > 0) {
$uniqueFile = false;
while ($uniqueFile == false) {
$randomName = random_name(20);
$randomName .= ".csv";
if (! file_exists(DIRECTORY . $randomName)) {
$uniqueFile = true;
}
}
$fp = fopen (DIRECTORY . $randomName, "w");
$write = fwrite( $fp, $csvLine );
fclose( $fp );
}
// email
$email_address = "address@host.com";
$email_from = "anotheraddress@host.com";
$email_text = "Hi, \n";
$email_text .= "\n";
$email_text .= "An application has just been received for the position: $jobtitle. Click here to view this file: \n";
$email_text .= "\n";
$email_text .= SITE_ADDRESS . DIRECTORY . $randomName . "\n";
mail($email_address, "Automated Csv", $email_text, $email_from);