Answer the question
In order to leave comments, you need to log in
What to write in request.php?
Hello!
Immediately reservation - a complete zero.
I can't figure it out for the third day.
There is a contact form that accesses a file on the server called request.php (apparently usually called mail.php). It is located not in the root of the site where index.html is, but in a separate folder named /request/. Its content is as follows:
<?php
if($_POST['id'] === "contact-center-form-2--0-form") {
$mailto = "";
$data_array = json_decode($_POST['data']);
$message = "";
foreach ($data_array as $key => $value) {
if (isset($value->name) && $value->name !== "") {
$message .= $value->name.': '. $value->value.'
';
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (RFC)
$eol = "\r\n";
// main header (multipart mandatory)
$headers = "From: $mailto" . $eol;
$headers .= "Reply-To: $mailto" . $eol;
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
$headers .= "Content-Transfer-Encoding: 7bit" . $eol;
$headers .= "This is a MIME encoded message." . $eol;
// message
$body = "--" . $separator. $eol;
$body .= "Content-Type: text/html; charset=iso-8859-1" . $eol;
$body .= "Content-Transfer-Encoding: 8bit" . $eol . $eol;
$body .= "" . $message. "" . $eol . $eol;
foreach( $_FILES as $file) {
if ( !move_uploaded_file( $file['tmp_name'], dirname(__FILE__) . '/../tmp/' . $file['name'] ) ) {
echo "error upload file: ". $file['name'];
continue;
}
$filename = $file['name'];
$path = dirname(__FILE__) . '/../tmp';
$file = $path . "/" . $filename;
$content = file_get_contents($file);
$content = chunk_split(base64_encode($content));
// attachment
$body .= "--" . $separator. $eol;
$body .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= "Content-Disposition: attachment" . $eol;
$body .= $content . $eol . $eol;
}
$body .= "--" . $separator. "--";
//SEND Mail
if (mail($mailto, $subject, $body, $headers)) {
echo "mail send ... OK"; // or use booleans here
} else {
echo "mail send ... ERROR!";
print_r( error_get_last() );
}
}
The question is how to fill it in correctly?
I tried all the options - always a blank page and in the address bar access to this file with data from the contact form.
The only thing the browser started to give out was a syntax error when it began to fill in:
if (mail($mailto, $subject, $body, $headers)) { - it seems clear that the first one is to whom, the second is the subject of the message, but I don’t understand further.
And it's not clear whether they ($mailto and $subject) need to be filled in if($_POST['id'] - the one at the very beginning. I
checked the server for sending messages using PHP, everything works.
Thank you.
Answer the question
In order to leave comments, you need to log in
You give a part of the code from which the application logic is not clear even to you (the whole code is available to you). How do you want someone to guess how it was intended by the programmer?
I can only guess, by turning on the telepath mode that the request.php file should be included in another file, the $mail/$subject variables should be declared (they are not in the code).
The code at the very beginning does not fill them either, it fills the smtp headers, but the envelope part is not filled.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question