0

I'm using a script to create an email message, but for some reason, it can't read the variables... Now, this isnt ordinary php syntax, because in the example I got it from, they used code like this:

$messageproper =
"New message:\n" .
" \n" .
"Full name: $fullname\n" .
"Email: $email\n" ;

Now, I tried this:

$messageproper =
    "New placed order:\n".
    "\n".
    "Ticket type: $orderdata['tickettype']\n".
    "From: $orderdata['from']\n".
    "To: $orderdata['to']\n";

But for some reason it gives errors in every line. So I tried this:

 $messageproper =
    "New placed order:\n".
    "\n".
    "Ticket type: ".$orderdata['tickettype']."\n".
    "From: ".$orderdata['from']."\n".
    "To: ".$orderdata['to']."\n";

But for some reason that just leaves every variable empty.

Because Im using a function processOrder() (where I declare and set all the variables) and sendOrder() (where I assemble the email), I already tried making the $orderdata array global, but that didn't work either.

This is the important part of the script that sends the email:

$content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ;
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
// ---------------------------- preparing the headers ----------------------------
$headers =
"From: \"$fullname\" <$email>" . $headersep . "Reply-To: \"$fullname\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.15.0" .
$headersep . 'MIME-Version: 1.0' . $headersep . $content_type ;

// ---------------------------- sending the email ----------------------------
if ($use_envsender) {
mail($mailto, $subject, $messageproper, $headers, $envsender );
}
else {
    mail($mailto, $subject, $messageproper, $headers );
}
header( "Location: $thankyouurl" );
exit ;

What could I be doing wrong here? Also, could someone explain to me what kind of syntax this is, for the $messageproper ? I've never seen such unlogic syntax before (however, now I think of it, I do: in MySQL queries, where you put a php variable in the request.)

1 Answer 1

1

As for using it inside string, use {$orderdata['tickettype']} instead of $orderdata['tickettype']. As for concatenating not working, check if you have your data defined in scope. (put global $orderdata; in both functions).

Sign up to request clarification or add additional context in comments.

12 Comments

Oh damn, I forgot global in the second function! But what kind of syntax is this, why doesnt it work like regular php syntax?
Leaving its merits aside, it is a regular php syntax.
Well, how would it now if ['tickettype'] is a part of your variable or not? hence curly braces. Now that it doesn't work, have you checked if the value is there, for instance, when you use the . concatenation?
Well, if you have no data in your variable, no syntax will put it there, check your logic. The warning is because you have no output buffering and output this alert before setting some header elsewhere.
This is for accessing the member of an object. I'd suggest that you visit php.net if you're going to work with this language (that I can not suggest in my right mind:)).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.