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

Link to comment
Share on other sites

This code works for me:

<?php
$to = "myemail@domain.com";
$name = "This is the name.";
$email = "This is the email.";
$comments = "This is a comment.";
$subject = "Subject Test";

$headers = 'From: mysite@domain.com' . "\r\n" .
	'Reply-To: mysite@domain.com' . "\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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.