我通过在我的
Custom Webform Comment
单元
如果其他人也面临同样的问题,这里是我在custom\u webform\u注释中插入的代码。模块文件。
/**
* Implements hook_mail().
*/
function custom_webform_comments_mail($key, &$message, $params) {
switch($key) {
case 'custom_webform_comments_email':
$message['subject'] = t('Submit Request Form update');
$message['body'][] = t('You have got a new comment and status update on your submitted form.',array('@site-name' => variable_get('site_name','example.com')));
$message['body'][] = t(variable_get('custom_webform_comments_email_text',''));
break;
}
}
在上述代码行之后,将以下代码放在数据库后面,在函数custom\u webform\u comments\u commentform\u submit()中插入查询,以便在每次注释更新后发送邮件。
function custom_webform_comments_commentform_submit($form, $form_state) {
$fv = $form_state['values'];
$insert1 = db_insert('custom_webform_comments')
->fields(array(
'cid' => NULL,
'comment' => $fv['addnew']['comment'],
'subject' => $fv['addnew']['subject'],
'nid' => $fv['addnew']['nid'],
'sid' => $fv['addnew']['sid'],
'commenter_user_id' => $fv['addnew']['commenter_user_id'],
'comment_parent' => '0',
'ts' => date("Y-m-d H:i:s")
))->execute();
if($insert1)
{
global $user;
$params = array(
'body' => $message,
'subject' => 'Website Information Request',
'headers'=>'simple',
);
$message = drupal_mail('custom_webform_comments', 'custom_webform_comments_email', $user->mail, language_default(), $params, 'test@example.com', TRUE);
if (!empty($message['result'])) {
watchdog('mail', 'Mail sent Successfully (from %from to %to) for comment update', array('%from' => $message['from'], '%to' => $message['to']), WATCHDOG_NOTICE);
//drupal_set_message("Mail sent!");
}
else{
watchdog('mail', 'Error sending e-mail (from %from to %to).', array('%from' => $message['from'], '%to' => $message['to']), WATCHDOG_ERROR);
drupal_set_message(t('Unable to send e-mail. Contact the site administrator if the problem persists.'), 'error');
}
}
return $insert1;
}
类似地,要在每次状态更新时获取邮件,请更新以下函数。
function custom_webform_comments_status_dbupdater($data) {
global $user;
//Insert values into database
$insert = db_insert('custom_webform_submission_status')
->fields(array(
'id' => NULL,
'status' => $data['status'],
'submit_time' => date("Y-m-d H:i:s"),
'nid' => $data['nid'],
'sid' => $data['sid'],
'user' => serialize($user)
))->execute();
if($insert)
{
global $user;
$params = array(
'body' => $message,
'subject' => 'Website Information Request',
'headers'=>'simple',
);
$message = drupal_mail('custom_webform_comments', 'custom_webform_comments_email', $user->mail, language_default(), $params, 'test@example.com', TRUE);
if (!empty($message['result'])) {
watchdog('mail', 'Mail sent Successfully (from %from to %to) for status update', array('%from' => $message['from'], '%to' => $message['to']), WATCHDOG_NOTICE);
//drupal_set_message("Mail sent!");
}
else{
watchdog('mail', 'Error sending e-mail (from %from to %to).', array('%from' => $message['from'], '%to' => $message['to']), WATCHDOG_ERROR);
drupal_set_message(t('Unable to send e-mail. Contact the site administrator if the problem persists.'), 'error');
}
}
return $insert;
}