Page 1 of 1

Strange problem with mail and heredocs

Posted: Tue Dec 28, 2010 2:30 am
by blainarm387
Hi all.

I think this is either my first or second post on here, but at any rate I'm pretty new to PHP, so I really need some help.

I'm creating a script that automatically sends an email to a person when I create an account for them on my service (it's a closed service that's invite-only). I want to send them a mail asking the user to click on a link to verify their account.

In order to send the mail, I used heredoc formatting, like so:

Code: Select all

$mail_body=<<<MAIL
To $first_name $last_name:

I have created an account for you on my service. Please click on the following link to activate it and choose a password:

$validation_url?email=$safe_email&validation_string=$validation_string

Please note that you will be unable to access your account until you complete the validation process.

Sincerely,

The staff at NFG Co, Ltd.
MAIL;
If I just echo $mail_body, it comes out fine in my browser, albeit without any line breaks. However, when I send the message as an actual mail, everything after the first line gets cut off. What's even stranger is that, by accident, I once forgot to define the variables $first_name and $last_name, and when I sent test mails under those circumstances, it also worked fine until the line with the validation link (i.e., the only other line with variables.

What's also stranger is that, just for kicks and giggles, I decided to paste the following code into my script to see what would happen:

Code: Select all

class foo
{
    var $foo;
    var $bar;

    function foo()
    {
        $this->foo = 'Foo';
        $this->bar = array('Bar1', 'Bar2', 'Bar3');
    }
}

$foo = new foo();
$name = 'MyName';

$message_body =  <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;

mail($email,$subject,$message_body);
?> 
This mail worked just fine, so I have no clue as to why my script does not. Any help would be greatly appreciated.

Regards,

Blain Armstrong.
Toride, Japan