Как получить вложение из Gmail?

1

У меня есть письмо для отправки электронной почты с приложением. Как это:

require_once "Mail.php";
require_once "Mail/mime.php";

$from = '[email protected]_from';
$to = '[email protected]';
$subject = 'You got new order at ' . gmdate("Y-m-d\TH:i:s\Z");
// text and html versions of email.
$text = 'Name: ' . strip_tags($_POST['customerName']) . "\r\n" .
        'Phone: ' . strip_tags($_POST['phone']) . "\r\n" .
        'Email: ' . strip_tags($_POST['email']) . "\r\n" .
        'Make: ' . strip_tags($_POST['make']) . "\r\n" .
        'Model: ' . strip_tags($_POST['model']) . "\r\n" .
        'Year: ' . strip_tags($_POST['year']) . "\r\n" .
        'Part: ' . strip_tags($_POST['part']) . "\r\n" .
        'Paint code: ' . strip_tags($_POST['paintCode']) . "\r\n";

$html = '<html><body>Name: ' . strip_tags($_POST['customerName']) . '<br>' .
        'Phone: ' . strip_tags($_POST['phone']) . '<br>' .
        'Email: ' . strip_tags($_POST['email']) . '<br>' .
        'Make: ' . strip_tags($_POST['make']) . '<br>' .
        'Model: ' . strip_tags($_POST['model']) . '<br>' .
        'Year: ' . strip_tags($_POST['year']) . '<br>' .
        'Part: ' . strip_tags($_POST['part']) . '<br>' .
        'Paint code: ' . strip_tags($_POST['paintCode']) . '</body></html>';

$file = '';
if ( 0 < $_FILES['image1']['error'] ) {
	//echo 'Error: ' . $_FILES['file1']['error'] . '<br>';
}
else {
	$file = 'uploads/' . $_FILES['image1']['name'];
	move_uploaded_file($_FILES['image1']['tmp_name'], $file);
}

$file = './' . $file; // attachment
$crlf = "\n";

$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
//$mime->setHTMLBody($html);
$mime->addAttachment($file, 'image/png');

//do not ever try to call these lines in reverse order
$body = $mime->get();

$headers = array(
	'From' => $from,
	'To' => $to,
	'Subject' => $subject
);
$mime->headers($headers);

Когда я открываю почту, я получаю следующее:

Изображение 174551

КАК ПОЛУЧИТЬ ФАЙЛ ПРИЛОЖЕНИЯ?

Спасибо и всего наилучшего.

Теги:
sendmail
email-attachments

2 ответа

0
Лучший ответ

Спасибо всем за помощь. Я нашел решение, которое должно использовать https://github.com/PHPMailer/PHPMailer вместо http://pear.php.net/manual/en/package.mail.mail-mime.php

Просто следуйте примеру PHPMailer. И вот результат:

Изображение 174551

Спасибо и всего наилучшего.

0

попробуй это.

   // now we'll process our uploaded files
   foreach($_FILES as $userfile){

      // store the file information to variables for easier access
      $tmp_name = $userfile['tmp_name'];
      $type = $userfile['type'];
      $name = $userfile['name'];
      $size = $userfile['size'];


      // if the upload succeded, the file will exist
      if (file_exists($tmp_name)){

         // check to make sure that it is an uploaded file and not a system file
         if(is_uploaded_file($tmp_name)){
      $file_path = 'uploads/' . $userfile['tmp_name'];
      move_uploaded_file($userfile['tmp_name'], $file_path);

            // open the file for a binary read
            $file = fopen($tmp_name,'rb');

            // read the file content into a variable
            $data = fread($file,filesize($tmp_name));



            // close the file
            fclose($file);

            // now we encode it and split it into acceptable length lines
            $data = chunk_split(base64_encode($data));
         }

         $message .= "--{$mime_boundary}\n" .
            "Content-Type: {$type};\n" .
            " name=\"{$name}\"\n" .
            "Content-Disposition: attachment;\n" .
            " filename=\"{$fileatt_name}\"\n" .
            "Content-Transfer-Encoding: base64\n\n" .
         $data . "\n\n";
      }
   }
        $message.="--{$mime_boundary}--\n";

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

echo 'success';

// Finally, destroy the session.
session_destroy();  
}

Ещё вопросы

Сообщество Overcoder
Наверх
Меню