function custom_mail_form() { $form['#attributes'] = array('enctype' => "multipart/form-data"); // $form['mail_to'] = array( '#type' => 'textfield', '#title' => t('E-mail'), '#required' => TRUE, ); $form['mail_subject'] = array( '#type' => 'textfield', '#title' => t('Subject'), '#required' => TRUE, ); $form['mail_body'] = array( '#type' => 'textarea', '#title' => t('Body'), '#required' => TRUE, ); $form['mail_attachment'] = array( '#type' => 'file', '#title' => t('Attachment'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Send'), ); return $form; }
function custom_mail_form_submit($form, &$form_state) { $folder = file_directory_path()."/mail/"; // , , $attachment = array(); // if ($file = file_save_upload('mail_attachment', array(), $folder)) { // $attachment[] = $file; // } // , , , if (module_exists('mimemail')) { // , $message_result = mimemail( // mimemail, variable_get('site_mail', ini_get('sendmail_from')), // $form_state['values']['mail_to'], // $form_state['values']['mail_subject'], // $form_state['values']['mail_body'], // HTML, , TRUE TRUE, // , plaintext array(), // check_plain($form_state['values']['mail_body']), // plaintext, check_plain() html $attachment, // files, '' // , ); // TRUE, if($message_result) // drupal_set_message("Mail was sent to ".$form_state['values']['mail_to']); else drupal_set_message("Mail was not sent to ".$form_state['values']['mail_to'], "error"); if(count($attachment)) file_delete($attachment[0]->filepath); // , } else{ drupal_set_message("Please install <a href="http://drupal.org/project/mimemail">Mime Mail</a> module ".$mail, "error"); // } }
Source: https://habr.com/ru/post/111541/
All Articles