Menu
Hi,
I’m looking for a php script to allow web users to email an attached document from a submission form, however I can’t find one that compiles with out errors/ has good documentation/readme file to get going with.
$attachment = new EmailAttachment($pathtofile, $mimetype);
if(!$attachment->Exists())
return false;
else
{
$this->Attachments[] = $attachment; //** add the attachment to list.
return true; //** attachment successfully added.
}
$theboundary = md5(uniqid("EMAIL"));
$headers = "From: $this->From " . EmailNewLine .
"Date: " . date("r", time()) . EmailNewLine;
if($this->Headers != null && strlen(trim($this->Headers)) > 0)
$headers .= $this->Headers . EmailNewLine;
$headers .= "X-Mailer: " . EmailXMailer . EmailNewLine .
"MIME-Version: 1.0" . EmailNewLine .
"Content-Type: multipart/mixed; " .
"boundary=$theboundary" . EmailNewLine . EmailNewLine .
"This is a multipart MIME message" . EmailNewLine .
EmailNewLine;
$theemailtype = "text/" . ($this->TextOnly ? "plain" : "html");
if($this->Charset == null)
$this->Charset = ($this->TextOnly ? EmailTextCharset : EmailHtmlCharset);
$thebody = "--$theboundary" . EmailNewLine .
"Content-Type: $theemailtype; charset=$this->Charset" .
EmailNewLine . "Content-Transfer-Encoding: 8bit" .
EmailNewLine . EmailNewLine . $this->Content . EmailNewLine .
EmailNewLine;
foreach($this->Attachments as $attachment)
{
$thebody .= "--$theboundary" . EmailNewLine . $attachment->ToHeader() .
EmailNewLine;
}
$thebody .= "--$theboundary--";
return mail($this->To, $this->Subject, $thebody, $headers);
if($mimetype == null || strlen(trim($mimetype)) == 0)
$this->ContentType = "application/octet-stream";
else
$this->ContentType = $mimetype;
$this->FilePath = $pathtofile; //** save the path to the file attachment.
$header = "Content-Type: $this->ContentType; " .
"name="" . basename($this->FilePath) . """ . EmailNewLine .
"Content-Disposition: attachment; filename="" .
basename($this->FilePath) . """ . EmailNewLine;
$header .= "Content-Transfer-Encoding: base64" . EmailNewLine .
EmailNewLine;
$thefile = fopen($this->FilePath, "rb");
$data = fread($thefile, filesize($this->FilePath));
$header .= chunk_split(base64_encode($data), 76, EmailNewLine) .
EmailNewLine;
return $header; //** return the headers generated by file.
0.1.9 — BETA 5.6