Hello,

does anyone has experience with this issue ?

I need a mailform and I have to post several fields.
-a taxonomyterm - in a dropdown populated by an sql query
-email
-street
-....

When I send the email, only the last field (in this case 'postcode') is being placed in the body of the mail.
How di I place the diffrent fields in the body of the mail ?

Thanx a lot for your help !

This is the code :

$result = db_query("SELECT tid,name FROM term_data WHERE vid=5 ORDER BY name");
while ($row = db_fetch_object($result)) {
$options[$row->tid] = $row->name;
}
$form .= form_select(t('Opleiding'), 'tid', $node->tid, $options);
$form .= form_hidden("to", "you@domain.be");
$form .= form_textfield("Uw naam", "from_name", "", 60, 128);
$form .= form_textfield("Uw Emailadres", "from_email", "", 60, 128, "Vul hierboven een geldig emailadres in");
$form .= form_textfield("Straat + nummer", "body", "", 60, 128, "Uw Straat en huisnummer eventueel ook  bus");
$form .= form_textfield("Postcode", "body", "", 60, 128, "De postcode van uw woonplaats");
$form .= form_textarea("Geef hier uw motivatie en specialisatiegebieden op aub. Wij zullen u dan zo spoedig mogelijk contacteren.", "body", "", 60, 15);
$form .= form_textfield("Gemeente", "body", "", 60, 128, "Uw gemeente of stad");

$form .= form_submit("Send email");
echo form($form, "post", "?q=form_mail");

Comments

Marc Bijl’s picture

Hi,

If you look in form_mail.module at function form_mail_send_email($edit), you'll find this part of code:

elseif ($key == "body") {
  $body = $value;
  break;
}

This means, when looping, every time the function sees a field defined as body (in your case, this is more than just one time), the body of the e-mail text will be refilled and gets this value.

I'm not a programmer, so what I'm saying now might be wrong. But, I think the module supposes there should be only one field defined as body. I also see a break in the code. So I think another assumption of the module is that the body's position is at the end of the form... (does that sound right?).

Anyway, instead of giving the e-mail text ($body) a new value, it should add the value to the existing value, created by the other (body-) fields. So I think better is:

elseif ($key == "body") {
  $body .= $value;
  break;
}

I'm not using form_mail.module anymore right now, but in the files I used before I found this code:

function form_mail_send_email($edit) {
  unset($edit["op"]);
  foreach ($edit as $key => $value) {
    if ($key == "to" && variable_get("form_mail_custom_to", 0)) {
      $to = $value;
    }

/**
 *	Revision of New Oceans starts here
 *
 *	! Body wordt hieronder direct beoordeeld, inclusief break;
 *	! Moet daarom in de php code als laatste veld worden genoemd
 */		

    elseif (($key == "body") && ($value == "")) {
      $body .= "\n\n" . t("<message empty>");
      break;
    }

    elseif (($key == "body") && ($value != "")) {
      $body .= "\n\n$value";
      break;
    }
		
    elseif ($value == "")  {
      $body .= "- " . t($key) . ": " . t("<empty>") . "\n";
    }
		
    else {
      $body .= "- " . t($key) . ": " . "$value" . "\n";
    }

/**
 *	Revision of New Oceans ends here
 */		

  }

  $subject = $edit["subject"] ? t("submission from %s", array ("%s" => variable_get("site_name", "your web site"))) . " - " . $edit["subject"] : t("submission from %s", array ("%s" => variable_get("site_name", "your web site"))) . " - " . t("no subject");
  $from_email = $edit["from_email"] ? $edit["from_email"] : variable_get("site_mail", ini_get("sendmail_from"));
  if ($name = $edit["from_name"]) {
    $name = mime_header_encode($name,'UTF-8');
    $headers = "From: $name ". " <". $edit["from_email"]. ">\n";
  }
  else {
    $headers = "From: $from_email \n";
  }
  if (!$to) $to = variable_get("form_mail_email", "");
  user_mail($to, $subject, $body, $headers);
}

Hope this can be helpful!

elv’s picture

As New Oceans said you can use "body" only once. And if you use it every other param seems to be lost...

But as long as you don't use "body" you can have any number of params :

$form .= form_textfield("Your name", "Name", "", 60, 128, "", "", $required = true);
$form .= form_textfield("Your email", "Email", "", 60, 128, "", "", $required = true);
$form .= form_textarea("Your address", "Address", "", 60, 5, "", "", "required");
$form .= form_textarea("Optionnal comment", "Comment", "", 60, 5);

and in the mail it will appear as :

Name: John
Email: Doe
Address: 1, infinite loop Cupertino
Comment: I love turnips

form_mail really needs docs...