Ik heb een stuk programmatuur gemaakt, waarbij ik met een HTML-formulier een bericht kan intikken, wat vervolgens in een default HTML-layout wordt gegoten en naar een adressenlijst wordt gemaild. Alles werkt prima, alleen in het bericht dat in het mailbericht komt te staan, zitten een aantal fouten. Deze staan onderaan mijn post vermeld, na een beknopte levering van mijn code.
Ik roep vanaf de verwerking van het HTML-formulier de mailfunctionaliteit aan als volgt:
$txtSubject en $txtMessage zijn hier variabelen die door het formulier zijn meegestuurd.
De functie mailinglist haalt alle adressen uit de mailinglist en stuurt per adres een mailtje met een persoonlijke aanhef. Het ingevulde bericht wordt gecontroleerd op HTML-tags en deze worden uit het bericht gehaald, op enkele toegestande tags na:
De email-functie:
De functie SafeHTML:
Als ik nu het bericht:
wil versturen, ziet dat er in de e-mail als volgt uit:
De vragen zijn deze:
1) Waarom wordt het stuk "in which men and women would be promiscuous" vervangen door "in which men an! d women would be promiscuous"? (Merk het uitroepteken op in het woord "and" op regel 4 van de codestukken.)
2) Bij de quotes worden diverse escape-backslashes geplaatst.
Bij beide problemen zoek ik naar een oplossing, maar kom ik er door zoeken op php.net niet echt uit...
Ik roep vanaf de verwerking van het HTML-formulier de mailfunctionaliteit aan als volgt:
PHP:
1
| mailinglist($txtSubject,$txtMessage); |
$txtSubject en $txtMessage zijn hier variabelen die door het formulier zijn meegestuurd.
De functie mailinglist haalt alle adressen uit de mailinglist en stuurt per adres een mailtje met een persoonlijke aanhef. Het ingevulde bericht wordt gecontroleerd op HTML-tags en deze worden uit het bericht gehaald, op enkele toegestande tags na:
PHP:
1
2
3
4
5
6
| function mailinglist($subject,$message){ while($row = mysql_fetch_object($result)){ $messageFinal = "Beste ".$row->naam.",<BR><BR>".$message."<BR><BR>".$disclaimer; email("De afzendernaam","hetafzender@adres.nl",$row->naam,$row->email,$subject,$messageFinal,"","","","",true); } } |
De email-functie:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| function email($fromname,$fromaddr,$toname,$toaddr,$subject,$message, $ccname, $ccaddr, $bccname, $bccaddr, $filterHTML){ $mail_header = "MIME-Version: 1.0\r\n"; $mail_header .= "Content-type: text/html; charset=iso-8859-1\r\n"; $mail_header .= "From: ".$fromname." <".$fromaddr.">\r\n"; if ($ccaddr != ''){ $mail_header .= "CC: ".$ccname." <".$ccaddr.">\r\n"; } if ($bccaddr != '') { $mail_header .= "BCC: ".$bccname." <".$bccaddr.">\r\n"; } $mail_header .= "Reply-To: ".$fromname." <$frommail>\r\n"; $mail_header .= "X-Priority: 3\r\n"; $mail_header .= "X-MSMail-Priority: Normal\r\n"; if($filterHTML){ $message = safeHTML($message); } $msg = $email_header; $msg .= trim(nl2br($message)); $msg .= $email_footer; $to = $toname." <".$toaddr.">"; mail($to,$subject,$msg,$mail_header) or die(mysql_error."<BR>Je e-mail is niet verstuurd.<BR><BR>Error No. 15"); } |
De functie SafeHTML:
PHP:
1
2
3
| function safeHTML($str) { return strip_tags($str,"<font><b><i><u><pre><br>"); } |
Als ik nu het bericht:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| For Diogenes the simple life meant not only disregard of luxury but also disregard of laws and customs of organized, and therefore "conventional," communities. The family was viewed as an unnatural institution to be replaced by a natural state in which men and women would be promiscuous and children would be the common concern of all. Though Diogenes himself lived in poverty, slept in public buildings, and begged his food, he did not insist that all men should live in the same way but merely intended to show that happiness and independence were possible even under reduced circumstances. The program for life advocated by Diogenes began with self-sufficiency, or the ability to possess within oneself all that one needs for happiness. A second principle, "shamelessness," signified the necessary disregard for those conventions holding that actions harmless in themselves may not be performed in every situation. To these Diogenes added "outspokenness," an uncompromising zeal for exposing vice and conceit and stirring men to reform. Finally, moral excellence is to be obtained by methodical training, or asceticism. |
wil versturen, ziet dat er in de e-mail als volgt uit:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| For Diogenes the simple life meant not only disregard of luxury but also disregard of laws and customs of organized, and therefore \\\"conventional,\\\" communities. The family was viewed as an unnatural institution to be replaced by a natural state in which men an! d women would be promiscuous and children would be the common concern of all. Though Diogenes himself lived in poverty, slept in public buildings, and begged his food, he did not insist that all men should live in the same way but merely intended to show that happiness and independence were possible even under reduced circumstances. The program for life advocated by Diogenes began with self-sufficiency, or the ability to possess within oneself all that one needs for happiness. A second principle, \\\"shamelessness,\\\" signified the necessary disregard for those conventions holding that actions harmless in themselves may not be performed in every situation. To these Diogenes added \\\"outspokenness,\\\" an uncompromising zeal for exposing vice and conceit and stirring men to reform. Finally, moral excellence is to be obtained by methodical training, or asceticism. |
De vragen zijn deze:
1) Waarom wordt het stuk "in which men and women would be promiscuous" vervangen door "in which men an! d women would be promiscuous"? (Merk het uitroepteken op in het woord "and" op regel 4 van de codestukken.)
2) Bij de quotes worden diverse escape-backslashes geplaatst.
Bij beide problemen zoek ik naar een oplossing, maar kom ik er door zoeken op php.net niet echt uit...