Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/20322-php-white-space-only/
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
Link to comment
https://forums.phpfreaks.com/topic/20322-php-white-space-only/#findComment-89501
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
Link to comment
https://forums.phpfreaks.com/topic/20322-php-white-space-only/#findComment-89505
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
Link to comment
https://forums.phpfreaks.com/topic/20322-php-white-space-only/#findComment-89518
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)
Link to comment
https://forums.phpfreaks.com/topic/20322-php-white-space-only/#findComment-89531
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)
Link to comment
https://forums.phpfreaks.com/topic/20322-php-white-space-only/#findComment-89532
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.