0

I have made mail function in PHP, I use mail_to function and simple mail has been sent but the attachment file didn't. in this code I want the user send any type of file in the mail If I use any code of attachment get the error in page and page not open anyone helps me?

if(isset($_POST['submit']))
{
    $pack = $_POST['pack']; 
    $position = $_POST['position']; 
    $name = $_POST['name'];
    $email = $_POST['email'];
    $re_no = $_POST['re_no'];
    $phone = $_POST['phone'];
    $rfc_no = $_POST['rfc_no'];
    $comment1 = $_POST['comment1'];
    $comment2 = $_POST['comment2'];
    $comment3 = $_POST['comment3'];
    $tandc = $_POST['tandc'];
    $tandc2 = $_POST['tandc2'];
    $file1 = $_POST['file1'];
    $file2 = $_POST['file2'];
    $file3 = $_POST['file3'];


    $to = 'bhupendra.w3ondemand@gmail.com';
    $subject = 'MUV Express Delivery Enqury';
    $headers = "From: $email";

    $message = "Package: $tp\r\n";
    $message = "Package2: $pack\r\n";
    $message = "Name: $name\r\n";
    $message .= "Email: $email \r\n";
    $message .= "Phone: $phone \r\n";
    $message .= "Re No: $re_no \r\n";
    $message .= "Position: $position \r\n";
    $message .= "R.F.C. No.: $rfc_no \r\n";
    $message .= "Comment1: $comment1 \r\n";
    $message .= "comment2: $comment2 \r\n";
    $message .= "comment3: $comment3 \r\n";
    $message .= "Check: $tandc \r\n";
    $message .= "Check2: $tandc2 \r\n";
    $message .= "File1: $file1 \r\n";
    $message .= "File2: $file2 \r\n";
    $message .= "File3: $file3 \r\n";

    $message .= "Brief Description: $briefdesc \r\n";

    $sent = mail($to, $subject, $message, $headers);
    $_SESSION["po"] = $_POST['position'];
    if($sent) {
        echo "Success";
        header("Location: http://dev.w3ondemand.com/development/muvexpress/profile.php");
    }
    else {
        echo "Failure";
        header("Location: http://dev.w3ondemand.com/development/muvexpress/negocios.php");
    }
}

1 Answers1

0

Please map your variables accordingly.

 <?php
$subject = 'Your message subject';
$encoded_content = chunk_split(base64_encode($your_file_content_here)); 

//header 
$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "From:".$your_from_email."\r\n"; 
$headers .= "Reply-To: ".$reply_to_email."\r\n";  
$headers .= "Content-Type: multipart/mixed;\r\n";  


//plain text  

$message .= "Content-Type: text/plain; charset=ISO-8859-1\r\n"; 
$message .= "Content-Transfer-Encoding: base64\r\n\r\n";  

//attachment  
$message .="Content-Type: $file_type; name=".$file_name."\r\n"; 
$message .="Content-Disposition: attachment; filename=".$file_name."\r\n"; 
$message .="Content-Transfer-Encoding: base64\r\n"; 
$message .="X-Attachment-Id: ".rand(1000, 99999)."\r\n\r\n";  
$message .= $encoded_content; 

$sentMailResult = mail($to, $subject, $message, $headers); 
?>
Suraj15689
  • 29
  • 4