Невозможно открыть файл вложения - PullRequest
1 голос
/ 21 января 2020

Я пытался отправить вложение с помощью sendgrid CURL, почта успешно отправлена, но я не могу открыть файл вложения (например, jpg, png, xls). входной файл будет изменен в соответствии с пользователем, а также файл не является правильным, как в исходном размере.

Я попытался отправить вложение, используя sendgrid CURL, письмо отправлено успешно, но я не могу открыть файл вложения (например, jpg, png, xls). входной файл будет изменен в соответствии с пользователем, а также файл не является правильным, как в оригинальном размере.

    <?php
    // use actual sendgrid username and password in this section
    $url = 'https://api.sendgrid.com/'; 
    $user = 'SGusername'; // place SG username here
    $pass = 'SGpassword'; // place SG password here
    // grabs HTML form's post data; if you customize the form.html parameters then you will need to reference their new new names here
    $name = $_POST['userName']; 
    $email = $_POST['userEmail']; 
    $user_Product = $_POST['userProduct']; 
    $message =  $_POST['userMessage']; 
    $fileName = $_FILES['file_attach']['name'];
    $filePath = dirname(__FILE__);

    $params = array(
        'api_user'  => "$user",
        'api_key'   => "$pass",
        'to'        => "myemail.com", // set TO address to have the contact form's email content sent to
        'subject'   => "Feedback", // Either give a subject for each submission, or set to $subject

        'html'      => "<html><head><title> Contact Form</title><body>
        Name: $name\n<br>
        Email: $email\n<br>
        Product: $user_Product\n<br>

        Message: $message <body></title></head></html>", // Set HTML here.  Will still need to make sure to reference post data names
        'text'      => "
        Name: $name\n
        Email: $email\n
        Subject: $subject\n
        $message",
        'from'      => "myemail.com", // set from address here, it can really be anything
        'files['.$fileName.']' => '@'.$filePath.'/'.$fileName. 

      );


    curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
    $request =  'https://api.sendgrid.com/api/mail.send.json';
    // Generate curl request
    $session = curl_init($request);
    // Tell curl to use HTTP POST
    curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt ($session, CURLOPT_POST, true);
    // Tell curl that this is the body of the POST
    curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
    // Tell curl not to return headers, but do return the response
    curl_setopt($session, CURLOPT_HEADER, false);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
    // obtain response
    $response = curl_exec($session);
    curl_close($session);

        if(!$response) //output success or failure messages
        {
            $output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
            die($output);
        }else{
            $output = json_encode(array('type'=>'message', 'text' => 'Hi '.$name .'.Thank you for your feedback.'));
            die($output);
        }



    exit();
    // print everything out
    print_r($response);
    ?>
...