Hallo,
ik heb een bestand gemaakt welke automatisch gemaild moet worden.
Het bestand *.txt komt aan, alleen zijn de /n er uit gehaald. Als ik het bestand via ftp opsla is het formaat correct, laat ik hem emailen dan haalt hij alle enters er uit.
Wat gaat er fout?
Ik gebruik hiervoor de volgende code:
$letter = $bestandsnaam;
$handle=fopen($bestandsnaam, 'r');
$f_contents=fread($handle, filesize($bestandsnaam));
$f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
$f_type=filetype($bestandsnaam);
fclose($handle);
# To Email Address
$emailaddress="ledenadministratie@123.nl";
# Message Subject
$emailsubject="Clieop03 bestand van ".date("Y/m/d H:i:s");
# Message Body
ob_start();
// require("emailbody.php"); // i made a simple & pretty page for showing in the email
$body=ob_get_contents(); ob_end_clean();
# Common Headers
$headers .= 'From: FvIB - Clieop03 <clieop03@123.nl>'.$eol;
$headers .= 'Reply-To: 123 <webmaster@123.nl>'.$eol;
$headers .= 'Return-Path: webmaster <webmaster@123.nl>'.$eol; // these two to set reply address
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: application/pdf; name=\"".$letter."\"".$eol;
// sometimes i have to send MS Word, use 'msword' instead of 'pdf'
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$letter."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
# Setup for text OR html -
$msg .= "--".$mime_boundary.$eol;
$htmlalt_mime_boundary = $mime_boundary."_htmlalt";
//we must define a different MIME boundary for this section for the alternative to work properly in all email clients
$msg .= "Content-Type: multipart/alternative; boundary=\"".$htmlalt_mime_boundary."\"".$eol;
# Text Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= "This is a multi-part message in MIME format.".$eol;
$msg .= "If you are reading this, please update your email-reading-software.".$eol;
$msg .= "+ + Text Only Email from Genius Jon + +".$eol.$eol;
# HTML Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;
//close the html/plain text alternate portion
$msg .= "--".$htmlalt_mime_boundary."--".$eol.$eol;
# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol;
# SEND THE EMAIL
ini_set(sendmail_from,'clieop03test@123.nl'); // the INI lines are to force the From Address to be used !
mail($emailaddress, $emailsubject, $msg, $headers);
ini_restore(sendmail_from);
ik heb een bestand gemaakt welke automatisch gemaild moet worden.
Het bestand *.txt komt aan, alleen zijn de /n er uit gehaald. Als ik het bestand via ftp opsla is het formaat correct, laat ik hem emailen dan haalt hij alle enters er uit.
Wat gaat er fout?
Ik gebruik hiervoor de volgende code:
$letter = $bestandsnaam;
$handle=fopen($bestandsnaam, 'r');
$f_contents=fread($handle, filesize($bestandsnaam));
$f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
$f_type=filetype($bestandsnaam);
fclose($handle);
# To Email Address
$emailaddress="ledenadministratie@123.nl";
# Message Subject
$emailsubject="Clieop03 bestand van ".date("Y/m/d H:i:s");
# Message Body
ob_start();
// require("emailbody.php"); // i made a simple & pretty page for showing in the email
$body=ob_get_contents(); ob_end_clean();
# Common Headers
$headers .= 'From: FvIB - Clieop03 <clieop03@123.nl>'.$eol;
$headers .= 'Reply-To: 123 <webmaster@123.nl>'.$eol;
$headers .= 'Return-Path: webmaster <webmaster@123.nl>'.$eol; // these two to set reply address
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: application/pdf; name=\"".$letter."\"".$eol;
// sometimes i have to send MS Word, use 'msword' instead of 'pdf'
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$letter."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
# Setup for text OR html -
$msg .= "--".$mime_boundary.$eol;
$htmlalt_mime_boundary = $mime_boundary."_htmlalt";
//we must define a different MIME boundary for this section for the alternative to work properly in all email clients
$msg .= "Content-Type: multipart/alternative; boundary=\"".$htmlalt_mime_boundary."\"".$eol;
# Text Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= "This is a multi-part message in MIME format.".$eol;
$msg .= "If you are reading this, please update your email-reading-software.".$eol;
$msg .= "+ + Text Only Email from Genius Jon + +".$eol.$eol;
# HTML Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;
//close the html/plain text alternate portion
$msg .= "--".$htmlalt_mime_boundary."--".$eol.$eol;
# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol;
# SEND THE EMAIL
ini_set(sendmail_from,'clieop03test@123.nl'); // the INI lines are to force the From Address to be used !
mail($emailaddress, $emailsubject, $msg, $headers);
ini_restore(sendmail_from);