Jump to content

Archived

This topic is now archived and is closed to further replies.

jrodd32

Handling Form Data, using a mailto: statement

Recommended Posts

This is a co-problem between php and html so I am not sure where to put it...but anyway...

I am trying to get the information that people are entering into my form into an email that is automatically sent to the proper people upon submit.  However, it is not working properly, it is not picking up the body of the message that I would like it to see.

Here is the code:

<a href="mailto:user1@webmail.khsaa.org,USER2@WEBMAIL.KHSAA.ORG,USER3@WEBMAIL.KHSAA.ORG?subject=<?php
      foreach($source as $concern)
        echo($concern);
        ?>?&body=<?php
          $explaination;
          ?>
          %OA%OA
          <?php
          $row[id];
          ?>
          %OA
          <?php
          $row[lname].$row[suffix].', '.$row[fname];
          ?>
          %OA
          <?php
          $row[homephone];
          ?>
          %OA
          <?php
          $row[workphone];
          ?>
          %OA
          <?php
          $row[email];
          ?>
          ">

Share this post


Link to post
Share on other sites
This is a bit messy... Are you sure this is how it looks or maybe the forum made it look this way?

Orio.

Share this post


Link to post
Share on other sites
<a href="mailto:jtackett@khsaa.org,MDAY@KHSAA.ORG,JLONG@WEBMAIL.KHSAA.ORG?subject=<?php
      foreach($source as $concern)
        echo($concern);
        ?>?&body=<?php
          $explaination;
          ?>
          %OA%OA
          <?php
          $row[id];
          ?>
          %OA
          <?php
          $row[lname].$row[suffix].', '.$row[fname];
          ?>
          %OA
          <?php
          $row[homephone];
          ?>
          %OA
          <?php
          $row[workphone];
          ?>
          %OA
          <?php
          $row[email];
          ?>
          ">

I must have missed some of it when I copied it...that is how it looks, that might actually be the problem, i am very new to php and having problems when i have to combine it and html

Share this post


Link to post
Share on other sites
sorry but i dont seem to understand the code as it is on the forum as a link to a email address try to use the code /code tags to see the code properly sorry.

Share this post


Link to post
Share on other sites
It is not posting what i am putting into the text box area, it is cutting alot of the code off. I will attach the file

[attachment deleted by admin]

Share this post


Link to post
Share on other sites
When posting your code prefix your code with [nobbc][code]<?php[/nobbc] and end it with [nobbc]?>[/code][/nobbc]. If your code contains any Javascript, change any [nobbc]<script>[/nobbc] tags to [nobbc]< script >[/nobbc]

Ken

Share this post


Link to post
Share on other sites
trying again...
[code]
<html>
<a href="mailto:jtackett@khsaa.org,MDAY@KHSAA.ORG,JLONG@WEBMAIL.KHSAA.ORG?subject=<?php
      foreach($source as $concern)
        echo($concern);
        ?>?&body=<?php
           $explaination;
           ?>
           %OA%OA
           <?php
          $row[id];
          ?>
          %OA
          <?php
          $row[lname].$row[suffix].', '.$row[fname];
          ?>
          %OA
          <?php
          $row[homephone];
          ?>
          %OA
          <?php
          $row[workphone];
          ?>
          %OA
          <?php
          $row[email];
          ?>
          ">
</html>
[/code]

By the way I can print out the data in all the fields of my php variables so I am gettting the information that I want it just isn't getting into the email properly

Share this post


Link to post
Share on other sites
I don't get any errors it just isn't sending the email to the people.  And when you hover over the code that is printed to the page it isn't formatted correctly at the bottom of the browser.  Ex.)

mailto:....?&subject=Issue?&body=        %OA%OA      %OA  %OA

there should be info where the blank spaces are.

Share this post


Link to post
Share on other sites
You do realize that the mailto href will just open up the client's email program with your information in the message (maybe). It does not send any email, plus the user can see who you're sending the information to and can change it.

It would be much better to use the internal mail function and send the email message directly from your PHP script.

Ken

Share this post


Link to post
Share on other sites
it;s best you work with this code ok.

[code]
<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
  'Reply-To: webmaster@example.com' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

[/code]

Share this post


Link to post
Share on other sites
Example only.

[code]
<?php

foreach($source as $concern);

$to      = $row['email'];

$subject = 'the subject';

$message = "

<br>

$concern

<br>

$row['id']

<br>

$row['lname'].$row['suffix'].', '.$row['fname']

<br>

$row['homephone']

<br>

$row['workphone']

<br>

$row['email'] ";

<br>

$headers = 'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

?>

[/code]

Share this post


Link to post
Share on other sites
I assume that mail function you are using is the one kenrbnsn was refering to?  Also, is: 'X-Mailer: PHP/' . phpversion(); exactally what I need to put or is that individual to my system.

Thanks for the help

Share this post


Link to post
Share on other sites
the mail function i provided was from php.net i use and always works for me.

good luck.

Share this post


Link to post
Share on other sites
Read about the mail() function in the [url=http://www.php.net/manual/en/function.mail.php]on-line manual[/url].

I have found that the easiest way to send POSTed data in a mail message is to use the [url=http://www.php.net/print_r]print_r()[/url] to create the body of the message. For example:
[code]<?php
$to = 'someone@example.com';
$from = "From: Some One <someoneelse@example.com\n";
$Subject = "The follow was just entered";
$bdy = array();
$bdy[] = bdy($_GET,'$_GET');
$bdy[] = bdy($_POST,'$_POST');
$bdy[] = bdy($_SERVER,'$_SERVER);
$body = implode("\n",$bdy) . "\n";
mail($to,$subject,$body,$from);

function bdy($a, $s) {
  $tmp = array();
  if (!$empty($a)) {
      $tmp[] = ' ----- ' . $s . ' ------';
      $tmp[] = print_r($a); }
  return(implode("\n",$tmp)."\n";
}?>[/code]

I put code similar to this at the start of many of my scripts while developing them so I can see whether the scrips are recieving the data I think I'm entering.  It can be an invaluable debugging tool if you are doing any sort of AJAX coding and it can tell you whether hackers are trying to break your scripts.

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.