Jump to content


Photo

PHP White Space only?


  • Please log in to reply
10 replies to this topic

#1 russia5

russia5
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 10 September 2006 - 07:50 PM

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!


<?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"; 
?> 


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

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 10 September 2006 - 08:02 PM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 10 September 2006 - 08:04 PM

Works for me! I only removed the extraneous blanks after <<<EOF and after EOF;

Ronald   8)
RTFM is an almost extinct art form, it should be subsidized.

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 10 September 2006 - 08:10 PM

Me too, but I had to tidy up the if statement too...

<?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"; 
     }
?>

Regards
Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 10 September 2006 - 08:28 PM

Your original IF statement was fine, why'd you change it. Not that it is wrong now ...

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#6 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 10 September 2006 - 08:32 PM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#7 maxic0

maxic0
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 10 September 2006 - 09:02 PM

Can someone explain to me what <<<EOF is please?

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

#8 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 10 September 2006 - 09:23 PM

It is a so called heredoc statement. I'll quote from the PHP documentation:

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.

See http://nl3.php.net/m...ypes.string.php
for more detailed info.

Ronald   8)
RTFM is an almost extinct art form, it should be subsidized.

#9 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 10 September 2006 - 09:25 PM

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

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)
RTFM is an almost extinct art form, it should be subsidized.

#10 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 10 September 2006 - 09:37 PM

Thanks Ronald, I'll bear that in mind.

Regards
Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#11 russia5

russia5
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 11 September 2006 - 12:11 AM

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 




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users