glennn.php Posted July 29, 2016 Share Posted July 29, 2016 this is tricky to explain: I have a raw php script, written by someone else, that sends an email to a list extracted from a CSV file. It requires that certain values in the file be manually edited each time it's used, such as the following: $mail->setFrom('email@email.com', 'From Name'); // <==== change email address, From Name $subject = "Subject Line"; // <==== Adjust this subject $html = ' html here '; // <==== include email html MagicParser_parse("test.csv","myRecordHandler","csv|44|1|34"); // <==== change 'test.csv' file name the function is called by simply calling this email.php file in the browser. I'd like to build a form that would a) edit these values/strings on the fly and then b) call the file in the browser. The thing is, it's been a while since I've messed with PHP forms to any extent, and I can't remember how to get started on something like this. And I'm not familiar at all with fopen and fwrite to edit strings like this without messing up the existing code (there's a lot of other code in the file that needs to be left alone, obviously). I'm hoping someone can help me with a starting point - an idea on how to get this thing going - whether to build the form right in the same file or to build one in another file that posts these values to this existing file... hopefully someone can understand what I'm asking, and thank you much for your help. regards, glenn Quote Link to comment https://forums.phpfreaks.com/topic/301688-editing-strings-in-an-existing-file-with-a-form/ Share on other sites More sharing options...
Jacques1 Posted July 31, 2016 Share Posted July 31, 2016 First off: The script is protected with a password or an equivalent mechanism, right? Because if anybody can send out e-mails simply by visiting the URL, that's obviously a problem. As to your question: You don't fwrite() to the script at all. This is insecure, cumbersome, error-prone and entirely unnecessary. What you do instead is use dynamic e-mail addresses and filenames. So you replace the current hard-coded strings with references like $_POST['email_address'] and $_POST['csv_path']. The script will then use whatever value has been submitted through the form instead of relying on predefined values. The form can and should be in the same file. If you don't fully understand how this works, I suggest you start with a small test script which merely echoes the form input. When this works, you can extend the script and integrate your current code. Quote Link to comment https://forums.phpfreaks.com/topic/301688-editing-strings-in-an-existing-file-with-a-form/#findComment-1535344 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.