Question

Am trying to create a mail form with attachment where the reply address is different from the received address. They receiving emails works properly but if you decide to reply to them, it adds mime-version to the end of the reply email. (ex: email@gmail.commime-version) See code below.

<?php

// Email address to which you want to send email
$to = $_POST["gut"];


$subject = $_POST["fieldSubject"];
$message = nl2br($_POST["fieldDescription"]);

/*********Creating Uniqid Session*******/

$txtSid = md5(uniqid(time()));

$headers = "";
$headers .= "From: ".$_POST["fieldFormName"]."<".$_POST["fieldFormus"].">\nReply-To: ".$_POST["fieldFormEmail"]."";

$headers .= "MIME-Version: 1.0" . "\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$txtSid."\"\n\n";
$headers .= "This is a multi-part message in MIME format.\n";

$headers .= "--".$txtSid."\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$headers .= "Content-Transfer-Encoding: 7bit\n\n";
$headers .= $message."\n\n";

/***********Email Attachment************/
if($_FILES["attachment"]["name"] != "")
{
    $txtFilesName = $_FILES["attachment"]["name"];

    $txtContent = chunk_split(base64_encode(file_get_contents($_FILES["attachment"]["tmp_name"]))); 
    $headers .= "--".$txtSid."\n";
    $headers .= "Content-Type: application/octet-stream; name=\"".$txtFilesName."\"\n"; 
    $headers .= "Content-Transfer-Encoding: base64\n";
    $headers .= "Content-Disposition: attachment; filename=\"".$txtFilesName."\"\n\n";
    $headers .= $txtContent."\n\n";
}

// @ is for skiping Errors //
$flgSend = @mail($to,$subject,null,$headers);  

if($flgSend)
{
    echo 'Your email as being sent successFully.';
}
else

{ ?>

Was it helpful?

Solution

What happens if you change:

$headers .= "From: ".$_POST["fieldFormName"]."<".$_POST["fieldFormus"].">\nReply-To: ".$_POST["fieldFormEmail"]."";

To

$headers .= "From: ".$_POST["fieldFormName"]."<".$_POST["fieldFormus"].">\nReply-To: ".$_POST["fieldFormEmail"]."\n";

Notice the \n at the end of the line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top