Function name must be a string

I am prety much beginner to php but just wondering why I get error here. Im glad if you helps me out :wink:

$to = '';
    $firstname = $_POST["fname"];
    $email= $_POST["email"];
    $text= $_POST["message"];
    $phone= $_POST["phone"];

    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= "From: " . $email . "\r\n"; // Sender's E-mail
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    $message ='<table style="width:100%">
            <td>'.$firstname.'  '.$laststname.'</td>
        <tr><td>email: '.$email.'</td></tr>
        <tr><td>phone: '.$phone.'</td></tr>
        <tr><td>Text: '.$text.'</td></tr>

    if (@mail($to, $email, $message, $headers))
        echo 'The message has been sent.';
        echo 'failed';



You are assigning POST values to variables, but you do not have any code to deal with what happens when there are no POST values to assign.

It could be done more than one way. Typically the assignment of POST values are wrapped with a


conditional and the assignment, and indeed the entire “mail” code is not run, if there is no POST.

There are a few other issues with the code, but doing that will stop the undefined errors and allow you to continue developing the script.

So yo want me to change $firstname = $_POST to if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) { ?

I did now I got this error

No. What I meant by “wrap” is to put the assignments, and probably the entire script (unless for some reason you want to mail() regardless), inside an if conditional. eg. in pseudo code

if ($some_condtion === true) { 
// run this code 
} else { 
// run this code instead 

The “$some_condition === true” in this case being the test for a POST array.

Testing and dealing with the various POST array members will still need to be done within the condional.

1 Like

Lol man If i Just do like this I upload the file here then you maybe can change whats need to change for the php script to work. Because im a completly noob and I so bad at english

I think you forgot to attach the payment?


Sorry, but that is not possible. As I posted previously there are several ways to write the code, and the decisions about how to go about it are up to you.

Maybe a modified version of my previous example will be more helpful?

if ($_SERVER['REQUEST_METHOD'] == 'POST') { // new line added before your existing code 
// ALL of your existing code here 
} // new line added after your existing code

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.