-1

So this is my code, everything looks OK, but can't send email, and no error are displayed. I think html code is not necessary, it's a simple form with upload field, which works fine.

 <?php

//echo "<pre>"; var_dump($_FILES); exit;

if (isset($_FILES['files'])) {
    $files_array = array();
    $file_count = count($_FILES['files']['name']);
    $file_keys = array_keys($_FILES['files']);

    for ($i=0; $i<$file_count; $i++) {
        foreach ($file_keys as $key) {
            $files_array[$i][$key] = $_FILES['files'][$key][$i];
        }
    }
}

$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date('Y.m.d');
$time = date('H:i:s');

$rn = "\r\n";
$to = 'asdds@gmail.com';
$from    = $_POST['email'];
$subject = "Support for: " . $_POST['module'];

$semi_rand = md5(time()); 
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

$body =  "<h3>Support for {$_POST['module']} module</h3>
            <p><strong>Name: </strong> {$_POST['fullname']} </p>
            <p><strong>Email: </strong> {$_POST['email']} </p>
            <p><strong>Site URL: </strong> {$_POST['site_url']} </p>
            <p><strong>Admin URL: </strong> {$_POST['admin_url']} </p>
            <p><strong>Module: </strong> {$_POST['module']} </p>
            <p><strong>Module modified: </strong> {$_POST['module_modified']} </p>
            <p><strong>Admin Username: </strong> {$_POST['admin_username']} </p>
            <p><strong>Admin Password: </strong> {$_POST['admin_password']} </p>
            <p><strong>FTP Host: </strong> {$_POST['ftp_host']} </p>
            <p><strong>FTP Name: </strong> {$_POST['ftp_name']} </p>
            <p><strong>FTP Password: </strong> {$_POST['ftp_password']} </p>
            <p><strong>Message: </strong> {$_POST['message']} </p>
            <p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";

$headers =  'From: ' . $from  . $rn .
                        'Reply-To: ' . $from  . $rn .
                        'MIME-Version: 1.0' . $rn .
                        'Content-Type: text/html; charset=UTF-8' .  $rn .
                        'Para: WebSite'  .  $rn .
                        'X-Mailer: PHP/' . phpversion();

foreach ($files_array as $file) {
    $content = file_get_contents($file['tmp_name']);
    $content = chunk_split(base64_encode($content));
    $body .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"{$file['name']}\"\n" . 
    "Content-Disposition: attachment;\n" . " filename=\"{$file['name']}\"\n" . 
    "Content-Transfer-Encoding: base64\n\n" . $content . "\n\n";
    $body .= "--{$mime_boundary}\n";
}

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

When i delete part about attachment files it works fine. If someone can help me ?

Lim Lon
  • 1
  • 1
  • are you testing this code on your localhost? debug your code, display your errors – hassan Apr 10 '18 at 10:48
  • Yeah, no errors are displayed. – Lim Lon Apr 10 '18 at 10:49
  • and, `ini_set('display_errors', true);error_reporting(E_ALL);` to display your script errors – hassan Apr 10 '18 at 10:51
  • Nope, it's not, i does not use localhost. When i delete part about attachment files, it works fine. No response with ini_set also. – Lim Lon Apr 10 '18 at 10:51
  • Manually constructing MIME messages? Wheres the debug dump and validation for the result? And obligatory see also: [PHP mail function doesn't complete sending of e-mail](//stackoverflow.com/q/24644436) – mario Apr 10 '18 at 11:03

1 Answers1

0

Wrap your mail function so you can have a glimpse as to what it is failing:

if !( mail($to,$subject,$body,$headers) ) {
  // Any useful feedback?
  print_r(error_get_last());
}

I will expand the answer when there is more information - I don't have enough reputation to comment.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
gtamorim
  • 140
  • 8