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', '[email protected]');
$from = variable_get('site_mail', '[email protected]');
$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?
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', '[email protected]');
I replaced recipient mail address instead of [email protected]
. But it didn't work.