0

I'll be thrilled with any solution that will do that. Here's what I've been trying:

I have an input form that gets variable info. I want to email using php mail(), the variable info that was input. I've put the php mail() later in the same html/php file (I haven't used js in here at all). I can't figure out how to access those input variable values, to put into the mail() function.

<form target="_blank" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <br>
Donation Amount $: <input type="text" name="amount" size="20"> <br>
Instructions to us: 
<textarea name="eventcardinstructions" rows=6 cols=60></textarea><br>
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_cart">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="submit">
etc.
</form>  <!-- closes the form and lets the user hit a submit button-->

This is collecting inputs from the user to send to paypal. It's working. The user inputs an amount into an input field and instructions into a textarea. The amount is sent to paypal. The textarea instructions ARE NOT SENT to paypal, which is what I want.

Later (before the form ends OR) after end of form and the submit button that sends this to paypal, I want to reference the "amount" and "instructions" in php mail() function. The mail() function is working and sends emails. It just ignores and doesn't send the variable amounts. So the emails say:

     Subjectline: Event Card
     Body contents:  Event card bought for 

The mail function is:

    <?php   
     // headers allow the email to recognize html with in the 
     // message & process it.
    $headers = "MIME-Version: 1.0\r\n";          
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";      
   $eventcardmsg = "Event card bought for " . $_POST['amount'];
   $eventcardmsg = $eventcardmsg .= $_POST['eventcardinstructions'];
   mail("email@ourdomain.net", "Event Card", $eventcardmsg, $headers);

?>

How do I setup amount and eventcardinstructions so the values are used?

I see a couple related q&as but can't figure it out from them. This answer is using it the same way I am by using the $_POST['variable']; but it's not working for me. https://stackoverflow.com/questions/30016669/how-do-you-save-a-inputs-value-in-a-variable

This one: Assign input form to a variable looks like it's using php in the middle of the html input form to set the variable. I could try that, but seems odd to need to, like I'm not understanding something.

Thanks!!

Community
  • 1
  • 1
curls
  • 382
  • 1
  • 3
  • 16
  • Not too sure about the paypal integration, but your form actually leads to paypal site (https://www.paypal.com/cgi-bin/webscr)...I don't know what that does but I suggest you set the form action as your own PHP script (which would handle the email) and if successful redirect to paypal or some such. Additionally I think the `$eventcardmsg = $eventcardmsg .= $_POST['eventcardinstructions'];` is wrong...it should be `$eventcardmsg .= $_POST['eventcardinstructions'];` – TomasH Sep 12 '15 at 20:01
  • I want the form to go to paypal. It's an add to cart input form that collects a few bits of info on the fly. I can try to send to my own php first, but there's a bunch of other paypal buttons on the page -- it will get messy. This should work somehow here? – curls Sep 12 '15 at 20:10
  • $evencardmsg is set to a string, then I'm appending the instructions. So I'm not following what's in error with the code. – curls Sep 12 '15 at 20:11
  • @tomasH thanks for the ideas! It just seems like there has to be a simple way to grab the values that have been set inside the input form, either while still inside or in the same html afterward. – curls Sep 12 '15 at 21:23
  • So $eventcardmsg = $eventcardmsg (and whatever else) is supposed to be .= not =? I can't seem to keep straight in my mind when to use the .= and when to use the = even though I have working examples I was referring back to. – curls Sep 12 '15 at 21:44

1 Answers1

0

First, as TomasH already pointed, your $eventcardmsg assignation is wrong.
Anyway it might be simplified like this:

$eventcardmsg =
    'Event card bought for ' . $_POST['amount'] . ' ' . $_POST['eventcardinstructions'];

(don't omit at least one space between amount and instructions)

Now if you keep getting an wrong email content, the main question in this issue is: are POST query parameters sent to your PHP script?
So you should test it with something simple like:

<?php
echo '<pre>' . print_r($_POST, true) . '</pre>';

Then if it shows empty parameters (or even those parameters not cited), you must examine the way you're sending data from the HTML page.
Again already pointed by TomasH, it might be somme inconsistency while you previously send data to Paypal: if you don't identify it, please edit your question to show us the whole Paypal process.


EDIT (trying to answer the multiple OP's comments)

Regarding string concatenation in general
You may concatenate as many strings as you want into a resulting string, using the . operator, so:

$a = 'A';
$b = 'BB';
$c = 'CCC';
echo $a . $b . $c; // prints ABBCCC

Regarding .=
Any operator (not only .) may be used in conjunction with =, as a shortcut to avoid repeating the 1st operand when it is also the result, so:

$result .= $ope2;
// the above expression is pretty equivalent to the one below
$result = $result . $op2;

Regarding comments related to your original issue
It's not clear what you exactly want now, because you said:

I don't really want to send the form to a php file of my own.

But your original question tells you can't emit a proper email, and to emit an email you must first send the form to the php file where you emit it!

Anyway, you should test like I previously suggested:

echo '<pre>' . print_r($_POST, true) . '</pre>';

This way, you will get the whole list of which POST query parameters are passed to your script: print_r() is the function that prints this list, and <pre> is the enclosing HTML tag that makes this print more readable.

Be careful to type the statement exactly: from your penultimate comment, I guess you typed something wrong.

cFreed
  • 4,404
  • 1
  • 23
  • 33
  • Your eventcardinstructions line answers something I'd been trying to figure out and finally given up on... namely how to string things together. When I'd tried it, it kept giving me syntax errors and when I searched I coudln't find a search combo of words that showed an example. It was driving me bonkers. – curls Sep 12 '15 at 21:42
  • So $eventcardmsg = $eventcardmsg (and whatever else) is supposed to be .= not =? I can't seem to keep straight in my mind when to use the .= and when to use the = even though I have working examples I was referring back to. – curls Sep 12 '15 at 21:44
  • I don't really want to send the form to a php file of my own. I'd like to send it to paypal. I just figure while inside the form after the user has input, or outside the form in the same file after user has hit submit, those variable values should be accessable. I can't figure out how though. – curls Sep 12 '15 at 21:45
  • I can try to run with the test you gave. I'm interested, what are pre? and print_r. I can probably look up print_r but pre will get lost in the search. – curls Sep 12 '15 at 21:47
  • Never mind. I wasn't focused. The pre is just your text phrase. I can't get echo to work at that point in the program. I had an echo phrase there before but it doesn't show up on the screen. – curls Sep 12 '15 at 21:58
  • Any more ideas? It's seems like a simple question, but I can't figure out what documentation to look at to see how to reference these as variables. The examples I found and linked to, look promising but I'm still not understanding something. – curls Sep 13 '15 at 00:03
  • Huh... a lot of comments! I tried to answer in my edit above. – cFreed Sep 14 '15 at 02:39
  • cFreed, thanks! Between this and another similar question I'd posted, I gained enough to be able to figure out a solution. I had to go to two buttons. There isn't a one button with two actions from clicking it, that I can find. Here's my (long winded) solution: http://stackoverflow.com/questions/32545127/input-form-can-inputs-be-accessed-as-variables/32578182#32578182 . Meanwhile, here I've learned about . and .= and print_r(), so that will come in very handy. So thanks! – curls Sep 15 '15 at 05:27