开发者

html form to edit php code

开发者 https://www.devze.com 2023-04-08 16:59 出处:网络
I\'m working on a project that allows users to edit PHP code in PHP file. I have a PHP page that uses the mail function to send emails. I want to allow the user to change the message sent out (in the

I'm working on a project that allows users to edit PHP code in PHP file.

I have a PHP page that uses the mail function to send emails. I want to allow the user to change the message sent out (in the mail function).

I know how to re-write over a file but how to edit it, I'm not sure...

So here's the mai开发者_JAVA技巧l function:

$name=$_POST['userName'];

$emaily=$_POST['userEmail'];

$email = "$sponsor_email"; 


$subject = "the subject"; 


$message = "This is the message I want the user to be able to edit."; 

mail($email, $subject, $message, "From: $user-email"); 

Now I've got the $message var printed out on in the html form (so the users can see what will be changed but i don't know how I'd go about actually writing the code to change it on from submit.

Any ideas?

Thanks!

Sorry guys....

I didnt explain the situation properly.

The php file with the mail function will not be used to send an email from that form. All i want the form to do is edit the php file basically. I don't want to send the email with this form, this is for users to edit the mail function. Hope thats more clear...


On your editing page, just do something like below:

$message = file_get_contents("path to message file");
echo "<textarea id=\"message\">".$message."</textarea>";

Then you can edit whatever the contents of the file were.

Might be better though if you used a database, and sanitized the user input - rather than saving everything to a file.


Put the textarea in the form named "message", then do $message = $_POST['message'];


create a PHP that read what is in the PHP file that contains code to be edited then print it out in a HTML textarea then make another file that will write that modified code in the PHP file that has the code(to be modified). You can use google find how to read and write in a file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号