PHP coding question

I am working on a little addon to send an e-mail notification once a text message comes in. I am a developer, but I have never worked with PHP.

I get the body of a text with

$AGI = new AGI();
$body2 = trim($argv[2]);

and if I send it in an e-mail with

$message = $body2;
mail($to, $subject, $message, $headers);

everything is fine.

But when I try to add something to the message, I fails.

$message = $body2 . “extra text”;

Any idea?

Try this:

$message = "$body2 extra text";

Great! Works. Thank you so much!

One more question:

How do I check if $body2 is empty?

if (empty("$body2")) {
(some command)
} else {
(other command)
}

I have tried various versions, but I could not get it running

If I get an MMS (picture message) the the body of the text seems to be empty. I don’t know any other way to check if it is a MMS.

I think length{} (or is it strlen() - I get PERL and PHP mixed up at this level) will serve your purpose. It seems to me that it returns the length of the variable turned into a string. Zero (0) means the string is empty.

Thank you.

if (strlen("$body2") == 0)

works.

All done!

No. negative.

Length always returns zero, so always TRUE.

$body2 is not always empty.

Remove the quotes.

Thank you. You guys are amazing!

Now I have my text message to email notifications running!

1 Like