PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Sendmail question
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Sendmail question

Réponse
 
LinkBack Outils de la discussion
Vieux 14/03/2008, 16h35   #1
nihilism machine
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Sendmail question

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@someone.com");
$mail->to("someoneelse@someoneelse.com");
$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);
}
}

?>


  Réponse avec citation
Vieux 15/03/2008, 23h01   #2
Manuel Lemos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sendmail question

Hello,

on 03/14/2008 12:35 PM nihilism machine said the following:
> 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


The problem is that you have specified quoted-printable encoding and
have not properly encoded all characters in the HTML.

I recommend that you a class that knows how to properly message bodies
with quoted-printable. I use the MIME message class. Take a look at the
test_simple_html_mail.php example script.

http://www.phpclasses.org/mimemessage


--

Regards,
Manuel Lemos

PHP professionals looking for PHP jobs
http://www.phpclasses.org/professionals/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h42.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10855 seconds with 10 queries