@fenya-fl

Почему на почту не приходит прикрепляемый файл с формы?

public function vacancy1() {
  if( ( $this->request->server[ 'REQUEST_METHOD' ] == 'POST' ) ) {

    if( !empty( $this->request->post[ 'name' ] ) ) {
      $name = html_entity_decode( $this->request->post[ 'name' ], ENT_QUOTES, 'UTF-8' );
    } else {
      $name = 'Имя не указано';
    }
    if( !empty( $this->request->post[ 'email' ] ) ) {
      $email = html_entity_decode( $this->request->post[ 'email' ], ENT_QUOTES, 'UTF-8' );
    } else {
      $email = 'Email не указано';
    }
    $tel = $this->request->post[ 'phone' ];

    $mail = new Mail( $this->config->get( 'config_mail_engine' ) );
    $mail->parameter = $this->config->get( 'config_mail_parameter' );
    $mail->smtp_hostname = $this->config->get( 'config_mail_smtp_hostname' );
    $mail->smtp_username = $this->config->get( 'config_mail_smtp_username' );
    $mail->smtp_password = html_entity_decode( $this->config->get( 'config_mail_smtp_password' ), ENT_QUOTES, 'UTF-8' );
    $mail->smtp_port = $this->config->get( 'config_mail_smtp_port' );
    $mail->smtp_timeout = $this->config->get( 'config_mail_smtp_timeout' );

    if(isset($_FILES['file'])) {
        if($_FILES['file']['error'] == 0) {
             $mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);
        }
    }

    $mail->setTo( $this->config->get( 'config_email' ) );
    $mail->setFrom( $this->config->get( 'config_email' ) );
    $mail->setReplyTo( $this->request->post[ 'email' ] );
    $mail->setSender( $name );
    $mail->setSubject( html_entity_decode( 'Резюме на НАЧАЛО КАРЬЕРЫ', ENT_QUOTES, 'UTF-8' ) );
    $mail->setText( "Резюме на НАЧАЛО КАРЬЕРЫ
                                           Имя: $name
                                           Телефон: $tel
                                           Email: $email" );

    $mail->send();
  }


  if( isset( $this->error[ 'email' ] ) ) {
    $data[ 'error' ] = $this->error[ 'email' ];
  } else {
    $data[ 'error' ] = '';
  }

  header( 'Content-Type: application/json' );
  print json_encode( $data );

}

Инпут такой:
<input type="file" name="file" id="file">
  • Вопрос задан
  • 145 просмотров
Пригласить эксперта
Ответы на вопрос 1
riot26
@riot26
<:З )~~
Может потому что вызываешь $mail->AddAttachment() до того, как создал $mail?
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы