4 Replies - 1153 Views - Last Post: 12 February 2009 - 01:42 AM Rate Topic: -----

#1 rrn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 18-January 09

SENDING EMAIL WITH ATTACHMENTS

Post icon  Posted 10 February 2009 - 03:23 AM

i want to attach a word or pdf document from website and email to an id..
the document that has to be attached is saved in ftp site. wats happening is tat , some document is getting attached but not the one in ftp..

my code is as follows


<?php
/**
 * class:		 sendmail.class.php
 * description:	class for sending HTML mails with attachments
 * created:		21.02.2003
 * last change:	19.12.2003
 */
	class sendmail
	{
		// Variable deklarieren
		var $emailheader = "";
		var $textheader = "";
		var $textboundary = "";
		var $emailboundary = "";
		var $charset = "";
		var $betreff = "";
		var $empfaenger = "";
		var $attachment = array();
		var $cc = array();
		var $bcc = array();

		// Constructor
		function sendmail()
		{
			$this->textboundary = md5(time());
			$this->emailboundary = md5(time());
			$this->charset = "ISO-8859-1";
		}

		// Funktion zum setzen des CharSet?s
		function SetCharSet($char)
		{
			$this->charset = $char;
		}


		// Funktion die ?berpr?ft ob die E-Mailadresse korrekt ist
		function Validate_email($mailadresse)
		{
			if(!preg_match("/[a-z0-9_-]+(\.[a-z0-9_-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})/i",$mailadresse))
			{
				die('Die E-Mailadresse '.$mailadresse.' ist nicht g?ltig!!!');
			}
			return $mailadresse;
		}

		// Von wem die Email kommt in den Header setzen
		function from($name,$email)
		{
			$this->emailheader .= 'From: '.$name.'<'.$email.'>'."\r\n";
		}

		// Funktion um den Adressaten anzugeben
		function to($to)
		{
			$this->empfaenger = $this->Validate_email($to);
		}

		// Funktion zum senden einer Kopie an Cc Empf?nger
		function cc($kopie_an_empfaenger)
		{
			$this->cc[] = $kopie_an_empfaenger;
		}

		// Funktion zum senden einer Kopie an Bcc Empf?nger
		function bcc($kopie_an_empfaenger)
		{
			$this->bcc[] = $kopie_an_empfaenger;
		}

		// Erstellt den Header der Mime-Mail
		function makeMimeMail()
		{
			if(count($this->cc) > 0)
			{
				$this->emailheader .= 'Cc: ';
				for($i=0;$i<count($this->cc);$i++)
				{
					if($i > 0) $this->emailheader .= ',';
					$this->emailheader .= $this->Validate_email($this->cc[$i]);
				}
				$this->emailheader .= "\r\n";
			}

			if(count($this->bcc) > 0)
			{
				$this->emailheader .= 'Bcc: ';
				for($j=0;$j<count($this->bcc);$j++)
				{
					if($j > 0) $this->emailheader .= ',';
					$this->emailheader .= $this->Validate_email($this->bcc[$j]);
				}
				$this->emailheader .= "\r\n";
			}
			$this->emailheader .= 'MIME-Version: 1.0'."\r\n";
		}

		// Funktion f?r den Betreff anzugeben
		function subject($subject)
		{
			$this->betreff = $subject;
		}

		// Textdaten in Email Header packen
		function text($text)
		{
			$this->textheader .= 'Content-Type: multipart/mixed; boundary="'.$this->textboundary.'"'."\r\n\r\n";
			$this->textheader .= '--'.$this->textboundary."\r\n";
			$this->textheader .= 'Content-Type: text/plain; charset="'.$this->charset.'"'."\r\n";
			$this->textheader .= 'Content-Transfer-Encoding:7bit'."\r\n\r\n";
			$this->textheader .= strip_tags($text)."\r\n\r\n";
			$this->textheader .= '--'.$this->textboundary."\r\n";
			$this->textheader .= 'Content-Type: text/html; charset="'.$this->charset.'"'."\r\n";
			$this->textheader .= 'Content-Transfer-Encoding:7bit'."\r\n\r\n";
			$this->textheader .= '<html><body>'.$text.'</body></html>'."\r\n\r\n";
			$this->textheader .= '--'.$this->textboundary.'--'."\r\n\r\n";
		}

		// Funktion zum anh?ngen f?r Attachments in der Email
			 	function attachment($datei)
		{
			// ?berpr?fen ob File Existiert
			if(is_file($datei))
			{
			
																					  // Daten der Datei einlesen, in das BASE64 Format formatieren und auf max 72 Zeichen pro Zeile
				// aufteilen
				$file['inhalt'] = fread(fopen($datei,"rb"),filesize($datei));
				$file['inhalt'] = base64_encode($file['inhalt']);
				$file['inhalt'] = chunk_split($file['inhalt'],72);
				
				// Header f?r Attachment erzeugen
				$attachment_header = '--'.$this->emailboundary."\r\n";
				$attachment_header .= 'Content-Type: application/octet-stream; name="'.basename($datei).'"'."\r\n";
								  $attachment_header .= 'Content-Disposition: attachment; filename="'.basename($datei).'"'."\r\n\r\n";
																					  $attachment_header .= 'Content-Transfer-Encoding: base64'.$file['inhalt']."\r\n";

				// Attachment mit Header in der Klassenvariable speichern
				$this->attachment[] = $attachment_header.$file['inhalt']."\r\n";
			}
		/*	else
			{
				die('Die Datei "'.$datei.'" existiert nicht...'."\r\n");
			}*/
		}

		// Funktion zum erstellen des Kompletten Headers der Email
		// Senden der Email
		function send()
		{
			$this->makeMimeMail();

			$header = $this->emailheader;

			// ?berpr?fen ob Attachments angeh?ngt wurden
			if(count($this->attachment)>0)
			{
				$header .= 'Content-Type: multipart/mixed; boundary="'.$this->emailboundary.'"'."\r\n\r\n";
				$header .= '--'.$this->emailboundary."\r\n";
				$header .= $this->textheader;

				if(count($this->attachment) > 0) $header .= implode("",$this->attachment);

				$header .= '--'.$this->emailboundary.'--';
			}
			else
			{
				$header .= $this->textheader;
			}
			// Versenden der Mail
			mail("$this->empfaenger",$this->betreff,"",$header);

			$this->deletememory();
		}

		// Diese Funktion ist nur zum testen
		function deletememory()
		{
			unset($this->emailheader);
			unset($this->textheader);
			unset($this->attachment);
		}
	}
?>




in the above code "$datei" is the path to the document in ftp.
pls give me a solution.. thanks

Is This A Good Question/Topic? 0
  • +

Replies To: SENDING EMAIL WITH ATTACHMENTS

#2 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: SENDING EMAIL WITH ATTACHMENTS

Posted 10 February 2009 - 06:59 PM

Does anybody that know German visit the PHP Forums?

I'd love to help.. but when trying to figure out what the code is trying to do... its impossible for me to decypher German variable names, comments, function names, ect...

If you read / write German, could you please translate it to english? It'd be MUCH easier to help you!

Thanks!
Was This Post Helpful? 0
  • +
  • -

#3 rrn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 18-January 09

Re: SENDING EMAIL WITH ATTACHMENTS

Posted 11 February 2009 - 12:14 PM

View Postpr4y, on 10 Feb, 2009 - 05:59 PM, said:

Does anybody that know German visit the PHP Forums?

I'd love to help.. but when trying to figure out what the code is trying to do... its impossible for me to decypher German variable names, comments, function names, ect...

If you read / write German, could you please translate it to english? It'd be MUCH easier to help you!

Thanks!


sorry i dont know german.. can u pls check the code whether it wil work correctly??? it wil be very helpful to me........
thanks for ur interest to help
Was This Post Helpful? 0
  • +
  • -

#4 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: SENDING EMAIL WITH ATTACHMENTS

Posted 11 February 2009 - 12:16 PM

I assume then you did not write this code?
We are not here to do your work for you we are here to help. Copy and paste of code does not count as an effort on your part.
Was This Post Helpful? 0
  • +
  • -

#5 rrn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 18-January 09

Re: SENDING EMAIL WITH ATTACHMENTS

Posted 12 February 2009 - 01:42 AM

View PostWilliam_Wilson, on 11 Feb, 2009 - 11:16 AM, said:

I assume then you did not write this code?
We are not here to do your work for you we are here to help. Copy and paste of code does not count as an effort on your part.


actually this code was written by somebody else.but now i am working on it... i askd for ur help to check whether the code is working correctly...
thanks....


View Postrrn, on 12 Feb, 2009 - 12:40 AM, said:

View PostWilliam_Wilson, on 11 Feb, 2009 - 11:16 AM, said:

I assume then you did not write this code?
We are not here to do your work for you we are here to help. Copy and paste of code does not count as an effort on your part.


actually this code was written by somebody else.but now i am working on it... i askd for ur help to check whether the code is working correctly...
thanks....

if u r not interested in checking the code .. its ok.. but can u help me in this??
i would like to send a link to a person by mail.. hows tat possible??
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1