Answer the question
In order to leave comments, you need to log in
How to attach the created file to the form and send it to the mail?
Hello everyone, please help, there is an html form with a textarea , if you write something in the textarea and press the SEND button, then a file with text from the textarea is created on the server , now how can I make it so that when the SEND button is pressed, the created file is sent to the mail ?
Form handler code:
<?php
extract($_REQUEST);
$file = fopen("form-data.txt","w+");
fwrite($file,"Text :");
fwrite($file, $textbox ."\n");
fclose($file);
header("location: index.php");
?>
Answer the question
In order to leave comments, you need to log in
Use some lib to send mail messages, let's say PHPMailer
The docs have an example of sending a message with an attachment.
//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);
.....
//Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/filename.txt', $_REQUEST['textbox']);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question