hd112
hd112

Reputation: 279

Posting text file using cURL command line and php script on receiver end

Using the command line interface I cannot for the life of me send a text file.

Here's the command line

curl -F "[email protected]" -F "name=Scott" http://www.mydomain.com/go.php

here's the PHP taken from this site but the example was using php for curl not commandline.

<?php
$recipient = "[email protected]";
if (empty($_POST)) {
    // We only accpet POSTs
    header('HTTP/1.0 403 Forbidden');
    exit;
} else {
    // Handle a POST
    $message .= "Submitted at ".date("F j, Y, g:i a")."\n\n";
    $message .= "Name:\n";
    $message .= $_POST['name']."\n\n";
    $message .= "-------------------------------------------\n\n";
    $message .= "Comments:\n\n";
    $message .= $_POST['comments']."\n\n";
    // Send message to email address
    $sent = mail($recipient, "Feedback", 
        $message, "From: Feedback <noreply@some_host.com>\r\n");

    if ($sent) {
?>
        <html>
        <body>
            Got POST and sent email:
            <pre><? echo $message; ?></pre>
        </body>
        </html>
<?php
    } else {
        // Return an error
        header('HTTP/1.0 500 Internal Server Error', true, 500);
        exit;
    }
}
?>

The thing returns correctly and echos the email it sends I don't get the text file contents. That part is blank. Tried a thousand things but no dice.

Upvotes: 2

Views: 1974

Answers (1)

John Watson
John Watson

Reputation: 2583

The -F syntax didn't work for me either. But this does:

curl --data-urlencode [email protected] --data-urlencode "name=Scott" http://www.mydomain.com/go.php

Upvotes: 2

Related Questions