Hi,
I’ve written a short php page that is supposed to simply email a csv file. The page works fine when the file is located in the same folder as the php file, but I can’t get it to work when the file is located on another website.
Here is a live version of the page: [url]http://10stoptours.com/emailer/sendemail.php
Please help!
Here is the code:
[code=php]
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
echo date(“D M d, Y G:i”).”.csv”;
// Settings
$name = “Registrar”;
$email = “my email [email protected]”;
$to = “$name <$email>”;
$from = “Registrar Sender “;
$subject = “Here is your attachment”;
$mainMessage = “Hi, here’s the file.”;
//$fileatt = “./WN2015_open.csv”;
$fileatt = “http://www.ro.umich.edu/timesched/pdf/WN2015_open.csv”;
$fileatttype = “application/csv”;
$fileattname = date(“D M d, Y G:i”).”.csv”;
$headers = “From: $from”;
// File
$file = fopen($fileatt, ‘rb’);
$data = fread($file, filesize($fileatt));
fclose($file);
// This attaches the file
$semi_rand = md5(time());
$mime_boundary = “==Multipart_Boundary_x{$semi_rand}x”;
$headers .= “nMIME-Version: 1.0n” .
“Content-Type: multipart/mixed;n” .
” boundary=”{$mime_boundary}””;
$message = “This is a multi-part message in MIME format.nn” .
“-{$mime_boundary}n” .
“Content-Type: text/plain; charset=”iso-8859-1n” .
“Content-Transfer-Encoding: 7bitnn” .
$mainMessage . “nn”;
$data = chunk_split(base64_encode($data));
$message .= “–{$mime_boundary}n” .
“Content-Type: {$fileatttype};n” .
” name=”{$fileattname}”n” .
“Content-Disposition: attachment;n” .
” filename=”{$fileattname}”n” .
“Content-Transfer-Encoding: base64nn” .
$data . “nn” .
“-{$mime_boundary}-n”;
// Send the email
if(mail($to, $subject, $message, $headers)) {
echo “The email was sent.”;
}
else {
echo “There was an error sending the mail.”;
}
?>
</body>
</html>
Thanks,
Alex