Jump to content

Contents of variable not echoing


jeeves245

Recommended Posts

Hey guys, hopefully this is an easy one...

 

In this line, the variables are not echoing out. The script runs without error though.

echo "Name: $name | E-mail: $email | Comments: $comments";

 

So I tried surround them with "" like so:

echo "Name: "$name" | E-mail: "$email" | Comments: "$comments"";

 

I get the error:

Parse error: syntax error, unexpected T_VARIABLE in /var/www/vhosts/mputers.co.nz/httpdocs/process.php on line 13

 

Anyone know the correct way to write that line? Variables definitely contain values.

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/177887-contents-of-variable-not-echoing/
Share on other sites

Variables definitely contain values.

Are you 100% positive?

 

Try:

echo "Name: " . $name . " | E-mail: " . $email . " | Comments: " . $comments . "";

 

I'm 100% positive.

 

And that line didn't work.

 

I guess I should probably be more specific about the code, as it may make a difference. It's part of code used to send an e-mail.

 

Here are the bits that matter:

 

$body = "Name: $name | E-mail: $email  | Comments: $comments ";
if (mail($to, $subject, $body, $headers)) {
  echo("sent");
} else {
  echo("failed");
}

 

The rest of the code works just fine, it's just not taking the variables...

This code works for me:

<?php
$to = "[email protected]";
$name = "This is the name.";
$email = "This is the email.";
$comments = "This is a comment.";
$subject = "Subject Test";

$headers = 'From: [email protected]' . "\r\n" .
	'Reply-To: [email protected]' . "\r\n" .
	'X-Mailer: PHP/' . phpversion();

$body = "Name: $name | E-mail: $email  | Comments: $comments ";

if (mail($to, $subject, $body, $headers))
{
	echo("sent");
}
else
{
	echo("failed");
	}
?>

Try the above code on a separate page and see if that works. If that works, then your variables are not being placed.

Archived

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

×
×
  • Create New...

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.