Jump to content

Fatal error: Can't use function return value in write context in D:\WWWRoot\effe


Recommended Posts

I'm trying to write an email.php script for my website: www.effectu.nl

 

Now i'm getting this error and do not know what to do with it.

 

<?//preferences
$message->to = "alex@effectu.nl";
$message->ref = "effectu.nl";

//check for POST and form send from effectu.nl
if($_POST&&preg_match("#".$message->ref."#i",$_SERVER['HTTP_REFERER'])):

$message->send=true;

function sanitize($input) {
    return ucfirst(trim(strip_tags($input)));
}

//check and sanitize POST fields
if(!empty(sanitize($_POST['name1'])))$data->name1=sanitize($_POST['name1']);
else $message->send=false;

if(!empty(sanitize($_POST['company'])))$data->company=sanitize($_POST['company']);
else $message->send=false;

if(!empty(sanitize($_POST['email'])))$data->email=sanitize($_POST['email']);
else $message->send=false;

if(!empty(sanitize($_POST['number'])))$data->number=sanitize($_POST['number']);
else $message->send=false;

if(!empty(sanitize($_POST['fax'])))$data->website=sanitize($_POST['fax']);
else $message->send=false;

if(!empty(sanitize($_POST['message1'])))$data->message1=sanitize($_POST['message1']);
else $message->send=false;

//if all POST fields are not empty, send!
if($message->send):

	//construction of the email
	$message->subject	= $data->name." stuurde een bericht vanaf effectu.nl";
	$message->headers = "From: ".$data->email." \r\n".
	"Reply-To: ".$message->to."\r\n".
	"X-Mailer: PHP/".phpversion();
	$message->message 	.= "Bericht verstuurd vanaf www.effectu.nl \r\n\r\n";
	$message->message 	.= "Naam: ".$data->name1." \r\n";
	$message->message 	.= "Bedrijf: ".$data->company." \r\n";
	$message->message 	.= "Email: ".$data->email." \r\n";
	$message->message 	.= "Telefoon: ".$data->phone." \r\n";
	$message->message 	.= "Website: ".$data->website." \r\n\r\n";
	$message->message 	.= "Bericht: ".$data->message1." \r\n";

	//send the email
	mail($message->to, $message->subject, $message->message, $message->headers);

endif;

endif;?>

 

Does anyone know the solution?

The problem is in this line

 

if(!empty(sanitize($_POST['name1'])))$data->name1=sanitize($_POST['name1']);

 

thankz!!!

alex

I might be wrong, but I think that when using if else, you have to use brackets {}

 

if(!empty(sanitize($_POST['name1']))) {
$data->name1=sanitize($_POST['name1']);
}else {
$message->send=false;
}

I might be wrong, but I think that when using if else, you have to use brackets {}

 

if(!empty(sanitize($_POST['name1']))) {
$data->name1=sanitize($_POST['name1']);
}else {
$message->send=false;
}

Using curly brackets in this is probably a better option.

You are using an alternative if else syntax.

so if you use and alternative if else you should not place the semicolon after the if line. instead use :

if($condition):
  //output if
else:
  //output else
endif;

 

 

I'm pretty sure or you could simply test it.

have a look on the manual elseif and look at the second code block.

It also would make sense if you compare it to python syntax

Well... there it is... not that I like it...

Well most cases I dislike that syntax too. How ever if you use it where there is a lot of html between it, then the readability does improve. That and I had less complaints from the designers who read my code.

I json_encode it :)

 

Ok. I said it a bit tongue in the cheek. The app I spend most of the time on has GUI created with ExtJS and gets all data from server by Ajax requests.

 

I know that sometimes mixing PHP with HTML is close to unevitable (template engines help a lot though)

Point is: they make you mix those in files separated from business logic. Sure, I can split my code myself without template engines... but template engine is like having someone watching over you, so that you don't take any shortcuts.

I just don't see the point in e.g. (Smarty):

<ul>
{foreach from=$myArray item=foo}
<li>{$foo}</li>
{/foreach}
</ul>

instead of

<ul>
<?php foreach ($myArray as $foo): ?>
<li><?php echo $foo ?></li>
<?php endforeach ?>
</ul>

 

With discipline and proper app design it shouldn't be a problem to keep it separated (and enforce it separated).

I just don't see the point in e.g. (Smarty):

<ul>
{foreach from=$myArray item=foo}
<li>{$foo}</li>
{/foreach}
</ul>

instead of

<ul>
<?php foreach ($myArray as $foo): ?>
<li><?php echo $foo ?></li>
<?php endforeach ?>
</ul>

 

With discipline and proper app design it shouldn't be a problem to keep it separated (and enforce it separated).

 

I'm really glad to see somebody say this. I've been harbouring a dirty little non-templating secret for a long time now and whenever I point out that I actually don't really feel like using a templating language to do exactly the same thing as ordinary PHP would do, I get howls of derision from Rails programmers ;)

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.