2

I have been working in a multistep customer-survey form and i am unable to configure and send mail after the form is successfully submitted.

Here's is code for submit handler,

function customer_survey_personal_details_submit($form, &$form_state) {
  $multstep_values = $form_state['multistep_values'];

  $module = 'customer_survey';
  $key = 'customer_survey_complete';

  $to = $multstep_values['personal_details']['email'] . '; ' . variable_get('site_mail', 'admin@example.com');
  $from = variable_get('site_mail', 'admin@example.com');

  $params = array(
    'body' => 'Thank you for filling in our survey. You have now been entered into our prize draw.',
    'subject' => 'Thank you for filling in our survey, ' . $multstep_values['personal_details']['name'],  
  );

  $language = language_default();
  $send = TRUE;
  $result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
  if ($result['result'] == TRUE) {
    drupal_set_message(t('Your message has been sent.'));
  }
  else {
    drupal_set_message(t('There was a problem sending your message and it was not sent.'), 'error');
  }       
}

I did configure my mail address in the $from variable but it didn't worked.

I am able to send email from other modules.

What could be the problem?

Can someone suggest me a possible solution?

Error message

UPDATE:

Thanks @Mołot for the dpr($result);. I found that the problem resides with my $to variable.If i explicitly give the recipient email address, the mail is sent successfully..

It will be helpful if someone could say what is the problem in this line of code,

$to = $multstep_values['personal_details']['email'] . '; ' . variable_get('site_mail', 'admin@example.com');

I replaced recipient mail address instead of admin@example.com. But it didn't work.

  • possible duplicate of How to programmatically send an email? – harshal Nov 27 '13 at 14:24
  • @harshal this question is probably not the duplicate of the above question..here i have all the necessary implementation required for sending an email from a module(which is also suggested in the other question)..but the code doesn't work.. – Lucky Nov 28 '13 at 5:44
  • @Lucky apparently you don't have "all the necessary implementation required for sending an email". What does your watchdog says about it? What's in system logs? What's the output of dpr($result);? Without that information we cannot help you. Also, drupal_mail expect you to implement hook_mail, and it seems you didn't so marking as duplicate seems justified. – Mołot Nov 28 '13 at 7:32
  • @Mołot i tried using dpr($result)..and it was showing this `Invalid address: FROMADDRESS@gmail.com; TOADDRESS@gmail.com You must provide at least one recipient email address..so i changed the $from and $to email address in the code above explicitly..and now it is working..what could be the problem in the $from and $to variables.. – Lucky Nov 28 '13 at 10:28
0

You should call hook_mail() function for it and enter the message, body and all other parameters inside it. drupal_mail() calls hook_mail()

Check this link : How to programmatically send an email?

0

I guess your server in not working properly or it is not configured properly.

Try to configure the Server properly and it would work properly.

  • if my server not configured properly..then how would the email functionality work in other modules..but not this one..? – Lucky Nov 28 '13 at 5:42

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.