<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FinalFrag.be &#187; e-mail</title>
	<atom:link href="http://finalfrag.be/blog/tag/e-mail/feed/" rel="self" type="application/rss+xml" />
	<link>http://finalfrag.be/blog</link>
	<description>De persoonlijke website van Massimo 'FinalFrag' Mertens</description>
	<lastBuildDate>Tue, 04 Aug 2009 07:08:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Een e-mail adres beter&#160;controleren</title>
		<link>http://finalfrag.be/blog/2009/05/een-e-mail-adres-beter-controleren/</link>
		<comments>http://finalfrag.be/blog/2009/05/een-e-mail-adres-beter-controleren/#comments</comments>
		<pubDate>Mon, 25 May 2009 14:01:02 +0000</pubDate>
		<dc:creator>FinalFrag</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Programmeren]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://finalfrag.be/blog/?p=225</guid>
		<description><![CDATA[Voor sommige projecten is het nodig dat je over een geldig e-mail adres van een gebruiker beschikt. CodeIgniter, ondertussen ieders favoriete framework, biedt echter alleen een controle aan op het formaat van het e-mail adres. Deze controle beperkt zich tot &#8216;zit er een @-teken in?&#8217; en &#8216;zit er een punt in na het @-teken?&#8217;. Voor [...]]]></description>
			<content:encoded><![CDATA[<p>Voor sommige projecten is het nodig dat je over een geldig e-mail adres van een gebruiker beschikt. CodeIgniter, ondertussen ieders favoriete framework, biedt echter alleen een controle aan op het formaat van het e-mail adres. Deze controle beperkt zich tot &#8216;zit er een @-teken in?&#8217; en &#8216;zit er een punt in na het @-teken?&#8217;. Voor de meeste websites is dit natuurlijk meer dan goed genoeg, maar soms moet je toch iets meer zekerheid hebben.<span id="more-225"></span></p>
<h3>Wegwerp-e-mail adressen</h3>
<p>Er zijn op het internet heel wat websites te vinden die e-mail adressen aanbieden die maar een tijdje blijven bestaan. Sommige onder jullie zullen misschien <a target="_blank" href="http://www.mailinator.com"  title="mailinator.com">mailinator.com</a> wel kennen. Op die website kan je elke mailbox raadplegen die onder dat domein valt. Wanneer je bijvoorbeeld op een website een registratieformulier moet invullen, kan je simpelweg piet@mailinator.com gebruiken. Achteraf ga je dan naar mailinator.com en raadpleeg je de mailbox van piet en klaar is kees&#8230; of piet in dit geval.</p>
<h3>De uitbreiding</h3>
<p>De oplossing is uiteraard een uitbreiding op de Email helper van CodeIgniter. We voegen een extra functie toe (is_valid_email) die controleert of het ingevoerde e-mail adres niet voorkomt in een lijst van geblokkeerde hosts. Uiteraard gebruiken we ook nog de standaard functie van CodeIgniter om het formaat te controleren.</p>
<p>Het enige dat je moet doen is in de system/application/helpers map een nieuw bestandje aan te maken met als naam MY_email_helper.php en de volgende code er in plaatsen:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> is_valid_email<span style="color: #009900;">&#40;</span><span style="color: #000088;">$address</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Blocked hosts</span>
    <span style="color: #000088;">$illegalHosts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'10x9.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'blockfilter.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'dandikmail.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'deadaddress.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'deadfake.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'despam.it'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'disposeamail.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'dodgit.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'dodgeit.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'emailias.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'gishpuppy.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'greensloth.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'guerrillamail.org'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'haltospam.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'hidzz.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'incognitomail.net'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'jetable.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'kasmail.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'litedrop.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'mailcatch.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'maileater.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'mailexpire.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'mailinator.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'mailnull.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'mailzilla.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'makemoneytradingstocks.org'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'mint.us.to'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'mt2009.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'mytempemail.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'mytrashmail.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'nospam4.us'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'nospamfor.us'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'pookmail.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'pourri.fr'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'shieldemail.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'shortmail.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'signed-first-edition.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'skeefmail.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'slopsbox.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'sneakemail.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spam.su'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spambox.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spambox.us'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spamcero.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spamcorptastic.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spamex.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spamfree24.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spamfree24.eu'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spamfree24.de'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spamfree24.info'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spemfree24.net'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spamfree24.org'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spamgourmet.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spamhole.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spamla.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spammotel.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'spam.la'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'tempemail.net'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'tempinbox.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'trashymail.com'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'wh4f.org'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'yopmail.com'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Check the format with the CodeIgniter function</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>valid_email<span style="color: #009900;">&#40;</span><span style="color: #000088;">$address</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Check the illegal hosts</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$illegalHosts</span> <span style="color: #b1b100;">as</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$illegalHost</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">stripos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$address</span><span style="color: #339933;">,</span> <span style="color: #000088;">$illegalHost</span><span style="color: #339933;">,</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$address</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'@'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// The address is valid</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Wanneer je nu op je website een e-mail adres wil controleren, kan je gewoon deze functie gebruiken als volgt:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">is_valid_email<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'massimo@finalfrag.be'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Zal true teruggeven</span>
is_valid_email<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'piet@mailinator.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Zal false teruggeven</span></pre></div></div>

<p>Aangezien we ons bestand MY_email_helper.php hebben genoemd, wordt dit bestand automatisch geladen door CodeIgniter wanneer je de Email helper inlaad. Om deze functie te kunnen gebruiken hoef je dus enkel het volgende te doen:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Nog meer hosts</h3>
<p>Indien je zelf nog meer hosts weet die wegwerp-e-mail adressen aanbieden, mag je mij gerust een lijstje bezorgen per e-mail, dan pas ik de functie aan. Ik hoop dat jullie er iets aan hebben.</p>
]]></content:encoded>
			<wfw:commentRss>http://finalfrag.be/blog/2009/05/een-e-mail-adres-beter-controleren/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Fouten ontvangen per&#160;e-mail</title>
		<link>http://finalfrag.be/blog/2009/05/fouten-ontvangen-per-e-mail/</link>
		<comments>http://finalfrag.be/blog/2009/05/fouten-ontvangen-per-e-mail/#comments</comments>
		<pubDate>Tue, 12 May 2009 12:27:08 +0000</pubDate>
		<dc:creator>FinalFrag</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Programmeren]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://finalfrag.be/blog/?p=240</guid>
		<description><![CDATA[Iedereen die al wel eens een website maakt, maakt het mee. Al is het maar een kleine website voor de lokale voetbalploeg, of een website voor het bedrijf van je pa (De Grill-Mobiel   ). Op een dag loopt er iets fout op de website en moeten de mensen jouw komen opzoeken om het [...]]]></description>
			<content:encoded><![CDATA[<p>Iedereen die al wel eens een website maakt, maakt het mee. Al is het maar een kleine website voor de lokale voetbalploeg, of een website voor het bedrijf van je pa (<a target="_blank" href="http://www.degrillmobiel.be"  title="De Grill-Mobiel">De Grill-Mobiel</a> <img src='http://finalfrag.be/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ). Op een dag loopt er iets fout op de website en moeten de mensen jouw komen opzoeken om het allemaal uit te leggen wat er juist fout ging. Meestal is de uitleg dan &#8216;ik klikte daar, of was het nu daar, of nee nee, daar klikte ik&#8217; en ben je nog geen stap korter bij het oplossen van het probleem, dat misschien toch bij die eerste klik al voorkwam.<span id="more-240"></span></p>
<p>Zou het niet veel leuker zijn als je automatisch een e-mail kon ontvangen wanneer er iets fout gaat op een van je projecten. Wanneer dan de mensen naar je toe komen met hun probleem kan je trots zeggen: &#8216;ja, dat heb ik gisteren al opgelost, dat werkt terug zoals het hoort&#8217;. Mits een kleine extensie te schrijven voor het <a target="_blank" href="http://www.codeigniter.com"  title="CodeIgniter framework">CodeIgniter framework</a> is dit zo simpel als 1, 2, 3. Of zelfs nog makkelijker, want je moet helemaal niet kunnen tellen.</p>
<h3>My_Log</h3>
<p>Om deze extensie te kunnen schrijven, moeten we eerst op zoek naar de library die instaat voor het opvangen van alle foutmeldingen. In het CodeIgniter framework is dit de Log klasse. We maken een nieuw bestand aan in de map system/application/libraries/ en noemen dit MY_Log.php. In dit bestand zetten we het volgende:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> MY_Log <span style="color: #000000; font-weight: bold;">extends</span> CI_Log
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$levels</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERROR'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'DEBUG'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'2'</span><span style="color: #339933;">,</span>  <span style="color: #0000ff;">'INFO'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'3'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ALL'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'4'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> write_log<span style="color: #009900;">&#40;</span><span style="color: #000088;">$level</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'error'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$msg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$php_error</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$config</span> <span style="color: #339933;">=&amp;</span> get_config<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'write_log'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            parent<span style="color: #339933;">::</span><span style="color: #004000;">write_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$level</span><span style="color: #339933;">,</span> <span style="color: #000088;">$msg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$php_error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$level</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$level</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email_log'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">TRUE</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">levels</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$level</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">levels</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$level</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'log_threshold'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$report</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'log_email_title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$report</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;strong&gt;Requested URI:&lt;/strong&gt;&lt;br /&gt;http://&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_REFERER'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$report</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Referer:&lt;/strong&gt;&lt;br /&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_REFERER'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$report</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;strong&gt;User host:&lt;/strong&gt;&lt;br /&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">gethostbyaddr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$report</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;strong&gt;Date:&lt;/strong&gt;&lt;br /&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d-m-Y H:i:s'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$report</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;strong&gt;Error:&lt;/strong&gt;&lt;br /&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$msg</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$report</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000088;">$headers</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'MIME-Version: 1.0'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Content-type: text/html; charset=iso-8859-1'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'From: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'log_email_from'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'log_email_address'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'log_email_title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$report</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Als je de broncode goed naleest zie je dat we enkele variabelen uit het config bestand van CodeIgniter uitlezen. We kunnen uiteraard niets uitlezen dat niet bestaat. Het is dan ook nodig de variabelen in kwestie aan te maken in het config bestand.</p>
<p>De fervente CodeIgniter gebruikers, waaronder ikzelf, willen uiteraard de Email klasse van CI gebruiken om de e-mail te versturen. Ik heb dit proberen te implementeren, maar dat is me niet gelukt. Om in een library aan het CI object te komen, moet je de get_instance() functie gebruiken. Deze functie wordt gedeclareerd <strong>nadat</strong> de Log klasse wordt geladen. Daardoor is het dus niet mogelijk op het CI object te verkrijgen in MY_Log, en is het dus ook niet mogelijk om de Email klasse te laden. Jammer, maar gelukkig doet de <a target="_blank" href="http://be.php.net/manual/en/function.mail.php"  title="PHP mail()">mail() functie</a> van PHP het ook helemaal goed.</p>
<h3>Het config bestand</h3>
<p>In config.php (te vinden in system/application/config/) moeten de volgende items worden toegevoegd:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Vanaf welk niveau moeten er fouten gerapporteerd worden (deze variabele staat al in het config bestand)</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'log_threshold'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// True als je wil dat er effectief naar het logbestand geschreven wordt</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'write_log'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// True als je een e-mail wil ontvangen wanneer er een fout optreedt</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email_log'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Het e-mail adres naar welk de e-mail wordt verstuurd</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'log_email_address'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'massimo@finalfrag.be'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Het onderwerp van het e-mail bericht</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'log_email_title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Project x foutmelding'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// De afzender van de e-mail</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'log_email_from'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Project x'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Het resultaat</h3>
<p>Elke keer wanneer er nu een foutmelding op de website komt, bijvoorbeeld wanneer een PHP variabele niet kan worden gevonden of wanneer er een pagina niet werd gevonden, krijgen we een e-mail waarin meer info staat over de foutmelding. Een foutmelding ziet er als volgt uit:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="plain" style="font-family:monospace;">REQUESTED URI:
http://www.finalfrag.be/blog/
&nbsp;
USER HOST:
213.219.133.127.adsl.dyn.edpnet.net
&nbsp;
DATE:
06-05-2009 19:37:29
&nbsp;
ERROR:
Severity: Warning --&gt; Cannot modify header information - headers already sent by (output started at /home/finalfrag.be/public_html/libraries/Exceptions.php:164)
/home/finalfrag.be/public_html/libraries/Smarty.php 99</pre></td></tr></table></div>

<p>Uit deze voorbeeldfoutmelding kunnen we afleiden dat er op http://www.finalfrag.be/blog/ al iets op het scherm getoond wordt voordat de sessie geladen wordt door CodeIgniter. Ook krijgen we meer informatie over de gebruiker die de foutmelding heeft veroorzaakt en wanneer.</p>
<p>Ik hoop dat deze blogpost je weer wat verder helpt in de mooie wereld van webontwikkeling. Vragen of opmerkingen passen zoals gewoonlijk mooi in het vakje hieronder.</p>
]]></content:encoded>
			<wfw:commentRss>http://finalfrag.be/blog/2009/05/fouten-ontvangen-per-e-mail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
