1

I am using the following code to send emails, but it doesn't work. What is wrong with it?

function yukerja_view_contact_import_form_submit($form, &$form_state){
  global $user;
  $c_user = user_load_by_name($user->name);
  $uid = $c_user->uid;
  $profile = profile2_load_by_user($uid, 'recruiter');
  $field = $profile->field_recruiter_company;
  $tid = $field['und'][0]['tid'];
  $term = taxonomy_term_load($tid);
  $company = $term->name;
  $query = db_select('import_contact');
  $query->fields('import_contact', array('name', 'email', 'company', 'operator_insert', 'status', 'matches'))
    ->condition('company', $company,'=')
    ->orderBy('name', 'ASC');
  $table = $query->execute();
  $a;
  $b;
  $email_user = array();
  foreach ($table as $key => $values) {
    $email_user[$key + 1] = array( 
      'name' => $values->name,
      'email' => $values->email,
      'company' => $values->company,
      'operator_insert' => $values->operator_insert,
      'matches' => $values->matches,
    );
  }

  $params = array();
  foreach ($form_state['values']['table_user'] as $key => $value) {
    if(!$value == 0) {
      $email = $email_user[$key]['email'];
      $params = array(
        'name'            => $email_user[$key]['name'],
        'email'           => $email,
        'company'         => $email_user[$key]['company'],
        'operator_insert' => $email_user[$key]['operator_insert'],
        'matches'         => $email_user[$key]['matches'],
        'link_jobklik'    => 'http://dev.yukerja.gotpantheon.com',
        'subject'         => 'Invitation',
        'body'            => 'body tes',
        'from'            => 'as'
      );

      $module = 'yukerja_view_contact';
      $key = 'key';
      $language = language_default();
      $from = $params['operator_insert'] . "@jobklik.com";
      $send = FALSE;
      $message = drupal_mail($module, $key, $email, $language, $params, $from, $send);

      $message['subject'] = $params['subject'];
      $message['body'] = array();
      $message['body'][] = "Invitation";
      $message['body'][] = $params['link_jobklik'];

      // Retrieve the responsible implementation for this message.
      $system = drupal_mail_system($module, $key);

      // Format the message body.
      $message = $system->format($message);

      // Send e-mail.
      $message['result'] = $system->mail($message);
      // drupal_mail('yukerja_view_contact', 'invitation', $email, language_default(), $params, $params['from'], TRUE);

    }   
  }
}
2
  • using d7 or d6.
    – monymirza
    Dec 10 '12 at 4:30
  • are you running this code on a localhost machine?
    – saadlulu
    Dec 10 '12 at 6:18
3

I think your code is good enough to send email, but you need SMTP server to send the mail (which you has not specified), in case you have a mail server , the easy solution is install SMTP module which needs the SMTP server address and your are good to send email.

This module allows Drupal to bypass the PHP mail() function and send email directly to an SMTP server. The module supports SMTP authentication and can even connect to servers using SSL if supported by PHP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.