Sendmail question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a link that i want to use as the body of an html email. here is the code i use:

	// Notify about comments
	public function emailComment($Link, $ID) {
	$mail = new SendMail();
   	$mail->SetCharSet("ISO-8859-1");
    	$mail->from("someone", "someone@xxxxxxxxxxx");
    	$mail->to("someoneelse@xxxxxxxxxxxxxxx");
    	$mail->subject("New Comment!");
$str = '<a href="http://www.mysite.com/permalink.php?ID='. $Link.'">Comment ID #'.$ID.'</a>';
    	$mail->text($str);
    	//$mail->attachment($fileName);
    	$mail->send();

Where link = a number.

the email that i get is:

So the email should be a link to: http://www.mysite.com/permalink.php?ID=120
but instead links to: http://www.mysite.com/permalink.php?ID%120

Here is the php sendmail library =

<?

class SendMail {

	public $emailheader = "";
	public $textheader = "";
	public $textboundary = "";
	public $emailboundary = "";
	public $charset = "";
	public $subject = "";
	public $empfaenger = "";
	public $attachment = array();
	public $cc = array();
	public $bcc = array();

	public function __construct() {
    	$this->textboundary = uniqid(time());
    	$this->emailboundary = uniqid(time());
    	$this->charset = "ISO-8859-1";
	}

	public function SetCharSet($char) {
    	$this->charset = $char;
	}

	public function Validate_Email($emailAddress) {
if(!preg_match("/[a-z0-9_-]+(\.[a-z0-9_-]+)*@([0-9a-z][0-9a- z-]*[0-9a-z]\.)+([a-z]{2,4})/i", $emailAddress)) {
			die('Invalid Email Address: '.$emailAddress);
    	}
    	return $emailAddress;
	}

	public function from($name, $email) {
    	$this->emailheader .= 'From: '.$name.'<'.$email.'>'."\r\n";
	}

	public function to($to) {
    	$this->empfaenger = $this->Validate_Email($to);
	}

	public function cc($cc) {
    	$this->cc[] = $cc;
	}

	public function bcc($cc) {
    	$this->bcc[] = $cc;
	}

	public 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";
	}

	public function subject($subject) {
    	$this->subject = $subject;
	}

	public function text($text) {
$this->textheader .= 'Content-Type: multipart/alternative; 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: quoted- printable'."\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: quoted- printable'."\r\n\r\n"; $this->textheader .= '<html><body>'.$text.'</body></html>'."\r\n \r\n";
    	$this->textheader .= '--'.$this->textboundary.'--'."\r\n\r\n";
	}

	public function attachment($fileName) {
    	if(is_file($fileName)) {
			$attachment_header = '--'.$this->emailboundary."\r\n" ;
$attachment_header .= 'Content-Type: application/octet-stream; name="'.basename($fileName).'"'."\r\n";
			$attachment_header .= 'Content-Transfer-Encoding: base64'."\r\n";
$attachment_header .= 'Content-Disposition: attachment; filename="'.basename($fileName).'"'."\r\n\r\n";
			$file['inhalt'] = fread(fopen($fileName,"rb"),filesize($fileName));
			$file['inhalt'] = base64_encode($file['inhalt']);
			$file['inhalt'] = chunk_split($file['inhalt'],72);
			$this->attachment[] = $attachment_header.$file['inhalt']."\r\n";
    	} else {
			die('ERROR - Invalid Filename: "' . $fileName . "\r\n");
    	}
	}

	public function send() {
    	$this->makeMimeMail();
    	$header = $this->emailheader;

    	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;
    	}
    	mail("$this->empfaenger",$this->subject,"",$header);
    	$this->deletememory();
	}

	public function deletememory() {
    	unset($this->emailheader);
    	unset($this->textheader);
    	unset($this->attachment);
	}
}

?>


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux