Jump to content

Archived

This topic is now archived and is closed to further replies.

russia5

PHP White Space only?

Recommended Posts

Hello.  I am trying to install an HTML email script.  I have found this same coding in two places including Zend Codex.  I get White space on both of them.  Can somebody tell me why?  Am I suppose to call this script to someplace else or something?  Thanks to all that try to help me!

[code]

<?php
    $to = "johndoe@fakedomain.com";
    $from = "janedoe@anotherfakedomain.com";
    $subject = "This is a test email";
    $message = <<<EOF
<html>
  <body bgcolor="#ffffff">
    <p align="center">
        <b>Hello World!</b>
    </p>
  </body>
</html>
EOF;

    $headers  = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";

    $success = mail($to, $subject, $message, $headers);
    if ($success)
        echo "The email to $to from $from was successfully sent";
    else
        echo "An error occurred when sending the email to $to from $from";
?>

[/code]

ie) when I call this page www.mysite.com/thispage.php  I get only white space.  I believe I should be getting some sort of text box to put my HTML email in.  Thanks again... Greg

Share this post


Link to post
Share on other sites
No, you shouldn't be getting a form, you should be getting one of two messages...

1. The email to johndoe@fakedomain.com from janedoe@anotherfakedomain.com was successfully sent

or

2. An error occurred when sending the email to johndoe@fakedomain.com from janedoe@anotherfakedomain.com

Regards
Rich

Share this post


Link to post
Share on other sites
Works for me! I only removed the extraneous blanks after <<<EOF and after EOF;

Ronald   8)

Share this post


Link to post
Share on other sites
Me too, but I had to tidy up the if statement too...

[code]
<?php
    $to = "myemail@hotmail.co.uk";
    $from = "janedoe@anotherfakedomain.com";
    $subject = "This is a test email";
    $message = <<<EOF
<html>
  <body bgcolor="#ffffff">
    <p align="center">
        <b>Hello World!</b>
    </p>
  </body>
</html>
EOF;

    $headers  = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";

    $success = mail($to, $subject, $message, $headers);
    if ($success) {
        echo "The email to $to from $from was successfully sent";
    }
    else {
        echo "An error occurred when sending the email to $to from $from";
    }
?>
[/code]

Regards
Rich

Share this post


Link to post
Share on other sites
Your original IF statement was fine, why'd you change it. Not that it is wrong now ...

Ronald  8)

Share this post


Link to post
Share on other sites
I got a parse error when I ran it.  I corrected the spaces after <<<EOF and EOF at the same time I fixed the IF statement, so I didn't know which had fixed it.  I didn't realise you didn't need the curley braces when coding an IF statement.

Learn something new everyday.

Rich

Share this post


Link to post
Share on other sites
Can someone explain to me what <<<EOF is please?

I googled it but i didn't understand anything that came up.

Share this post


Link to post
Share on other sites
It is a so called heredoc statement. I'll quote from the PHP documentation:
[quote]Another way to delimit strings is by using heredoc syntax ("<<<"). One should provide an identifier after <<<, then the string, and then the same identifier to close the quotation.

The closing identifier must begin in the first column of the line. Also, the identifier used must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore.
[/quote]
See [url=http://nl3.php.net/manual/en/language.types.string.php]http://nl3.php.net/manual/en/language.types.string.php[/url]
for more detailed info.

Ronald   8)

Share this post


Link to post
Share on other sites
[quote author=HuggieBear link=topic=107573.msg431788#msg431788 date=1157920372]
I got a parse error when I ran it.  I corrected the spaces after <<<EOF and EOF at the same time I fixed the IF statement, so I didn't know which had fixed it.  I didn't realise you didn't need the curley braces when coding an IF statement.

Learn something new everyday.

Rich
[/quote]
Huggybear : you don't need to enclose the IF or ELSE action between curly braces if and only if it is a single statement. Also goes for some other statements such as FOR, etc.

Ronald  8)

Share this post


Link to post
Share on other sites
You guys are Cool!  Fixed it with the info.  Twice I run into that white space problem now with PHP.  Guess that might be a generic thing.  Also, I had the same parse error and the missing quotes thing fixed it.  Thanks Rich, Ronald and maxic0 

Share this post


Link to post
Share on other sites

×

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.