how to send a variable in a mail () of several parts?

0

Good morning, The problem I have is with a code to send emails with attachments that I found on the web and I want to modify it to send a variable, however when placing the variable it does not arrive in the mail, and verify that the variable is not empty so I guess it will be my mistake or something I do not know yet.

    $id=$_GET['id'];

        //The form has been submitted, prep a nice thank you message
    $output = '<h1>!</h1>';
    //Set the form flag to no display (cheap way!)
    $flags = 'style="display:none;"';

    //Deal with the email
    $to = '[email protected]';
    $subject = 'Subasta slip';

    $message = strip_tags($_POST['message']);
    $attachment = 
    chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
    $filename = $_FILES['file']['name'];

    $boundary =md5(date('r', time())); 

    $headers = "From: [email protected]\r\nReply-To: [email protected]";
    $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";

    $message="This is a multi-part message in MIME format.

 --_1_$boundary
 Content-Type: multipart/alternative; boundary=\"_2_$boundary\"

 --_2_$boundary
 Content-Type: text/html; charset=\"iso-8859-1\"
 Content-Transfer-Encoding: 7bit
 //********************aquí es donde quiero enviar la variable****************
<h2>ID del producto</h2>
<p>".$id."</p> 

$message

--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

$attachment
--_1_$boundary--";

    mail($to, $subject, $message, $headers);

As a side note, I can use any way to send the variable, I just need to see it somewhere. Thanks in advance

    
asked by Jamr07 13.11.2017 в 10:25
source

1 answer

0

As I mentioned in the comment, there is no need to escape the ID again.

The code has two problems:

  • The variable ID is not defined, if you define it above there should be no problem.
  • A space is missing after coding, it has to go on a spaced line.

link

I created a GIST because the code here in Stack did not escape me correctly, I replaced the email with XXX, remember to change it.

Tested and working with the DEMO data that I put. If you have verified that said data is collected and are correctly declared and processed, it should work as it is pasted to you (removing my evidence clearly).

Greetings,

    
answered by 13.11.2017 в 11:29