Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.)

share|improve this question

1 Answer

up vote 1 down vote accepted

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).

share|improve this answer
Oh damn, I forgot global in the second function! But what kind of syntax is this, why doesnt it work like regular php syntax? – laarsk Dec 4 '11 at 11:30
Leaving its merits aside, it is a regular php syntax. – Michael Krelin - hacker Dec 4 '11 at 11:30
1  
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? – Michael Krelin - hacker Dec 4 '11 at 11:45
1  
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. – Michael Krelin - hacker Dec 4 '11 at 11:51
1  
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:)). – Michael Krelin - hacker Dec 4 '11 at 12:07
show 8 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.