Newlines not being interpreted when passed to php via the command line

Posted by CarbonX on Stack Overflow See other posts from Stack Overflow or by CarbonX
Published on 2010-04-14T18:02:09Z Indexed on 2010/04/14 18:03 UTC
Read the original article Hit count: 237

I have a PHP script that I'm invoking from another shell script that sends an automated email with a message generated from the shell script. Problem is, when I send the message all the newline characters are printed into the message. How do I get them to be interpreted?

sendmail.sh:

/path/to/phpscript/sendmail.php "Some Message With Newlines\nHello World.\n"

sendmail.php:

$message = $argv[1] . "\nNewline";
$smtp->send($to, $from, $message);

The odd thing is the \n after the $argv variable is interpreted and actually prints Newline on a new line, but the newlines in the $argv variable don't, I have tried wrapping the variable in double quotes among other things but so far to no avail.

© Stack Overflow or respective owner

Related posts about php

Related posts about command-line-arguments