<?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>PHP Log &#187; Mail</title>
	<atom:link href="http://www.php-log.de/programmierer/php/mail/feed" rel="self" type="application/rss+xml" />
	<link>http://www.php-log.de</link>
	<description>Eine feine Sammlung nützlicher PHP Notizen</description>
	<lastBuildDate>Thu, 27 May 2010 04:43:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>CakePHP: E-Mails über die Shell versenden</title>
		<link>http://www.php-log.de/496/php/cakephp-e-mails-uber-die-shell-versenden</link>
		<comments>http://www.php-log.de/496/php/cakephp-e-mails-uber-die-shell-versenden#comments</comments>
		<pubDate>Tue, 02 Feb 2010 12:55:44 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=496</guid>
		<description><![CDATA[Es gibt verschiedene kleiner Hürden die umschifft werden wollen, bevor man mit einer Shell ordentliche E-Mailversenden kann. Hier nun ein kleines Schnippsel wie es bei mir zur Zeit funktioniert, eines der Hauptprobleme die ich hatte war das Nutzen der Templates. &#60;?php App::import&#40;'Core', 'Controller'&#41;; App::import&#40;'Component', 'Email'&#41;; &#160; $this-&#62;Controller =&#38; new Controller&#40;&#41;; $this-&#62;Email =&#38; new EmailComponent&#40;null&#41;; $this-&#62;Email-&#62;Controller [...]]]></description>
			<content:encoded><![CDATA[<p>Es gibt verschiedene kleiner Hürden die umschifft werden wollen, bevor man mit einer Shell ordentliche E-Mailversenden kann. <span id="more-496"></span></p>
<p>Hier nun ein kleines Schnippsel wie es bei mir zur Zeit funktioniert, eines der Hauptprobleme die ich hatte war das Nutzen der Templates.</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>
App<span style="color: #339933;">::</span><span style="color: #004000;">import</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Core'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Controller'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
App<span style="color: #339933;">::</span><span style="color: #004000;">import</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Component'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Controller</span> <span style="color: #339933;">=&amp;</span> <span style="color: #000000; font-weight: bold;">new</span> Controller<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span> <span style="color: #339933;">=&amp;</span> <span style="color: #000000; font-weight: bold;">new</span> EmailComponent<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Controller</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Controller</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">to</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Project Notifier &lt;rk@fakeadressdotfake.de&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bcc</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Project Notifier &lt;rk@fakeadressdotfake.de&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">replyTo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Project Notifier &lt;rk@fakeadressdotfake.de&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Project Notifier &lt;rk@fakeadressdotfake.de&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Wichtig</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">charset</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'UTF8'</span><span style="color: #339933;">;</span>	
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'client'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$clients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/496/php/cakephp-e-mails-uber-die-shell-versenden/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>554 Helo command rejected: Sorry, localhost is local, not remote</title>
		<link>http://www.php-log.de/404/php/554-helo-command-rejected-sorry-localhost-is-local-not-remote</link>
		<comments>http://www.php-log.de/404/php/554-helo-command-rejected-sorry-localhost-is-local-not-remote#comments</comments>
		<pubDate>Fri, 31 Jul 2009 16:13:57 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[SMTP]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=404</guid>
		<description><![CDATA[Vollkommen unerwartet bekomme ich nun diese Fehlermeldung beim Versenden einer E-Mail via SMTP mit der CakePHP Mail Komponente. 554 Helo command rejected: Sorry, localhost is local, not remote. Bei einer anderen Anwendung, die identischen Code verwendet und ebenfalls auf meinen lokalen Rechner läuft klappt der E-Mail-Versand. WTF&#8230; Weder Google noch Bing finden etwas relevantes für [...]]]></description>
			<content:encoded><![CDATA[<p>Vollkommen unerwartet bekomme ich nun diese Fehlermeldung beim Versenden einer E-Mail via SMTP mit der CakePHP Mail Komponente. 554 Helo command rejected: Sorry, localhost is local, not remote. Bei einer anderen Anwendung, die identischen Code verwendet und ebenfalls auf meinen lokalen Rechner läuft klappt der E-Mail-Versand. WTF&#8230;<span id="more-404"></span></p>
<p>Weder Google noch Bing finden etwas relevantes für diese Fehlermeldung. Ich habe noch ein leise Erinnerung an die Probleme die, je nach Provider, mit dem <a title="SMTP Problem" href="http://www.php-log.de/343/php/smpt-450-sender-address-rejected-domain-not-found" target="_blank">SMTP Versand</a> auftreten können. Glücklicherweise stoplterte ich aber im Cake Handbuch über die <a href="http://book.cakephp.org/de/view/481/Sending-A-Message-Using-SMTP" target="_blank">Dokumentation zur Mail Komponente </a>und die weisen Jungs bei CakePHP haben eine Lösung. Es ist der Sendeparameter &#8216;client&#8217;, den ich zuvor nie benötigte und der laut Doku nur bei nicht RFC 821 konformen SMTP Servern benötigt wird. Sobald ich für &#8216;client&#8217; den Host des SMTP Server (oder irgendeinen anderen) eingetragen habe funktioniert der Mailversand.</p>
<p>Warum es vom gleichen Host mit den gleichen SMTP Daten einmal funktioniert und ein anderes mal nicht will sich mir aber trotzdem nicht erschliessen. Naja, es mir aber auch niemals jemand versprochen, dass man als PHP Programmierer ausschliesslich auf einer Blümchenwiese lebt <img src='http://www.php-log.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Achso, hier auch noch das entsprechende Codesample:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> prepareSmtpSending<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">smtpOptions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	    <span style="color: #0000ff;">'port'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">,</span> 
	    <span style="color: #0000ff;">'timeout'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span>
	    <span style="color: #0000ff;">'host'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'mail.irgendwo.de'</span><span style="color: #339933;">,</span>
	    <span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'hans'</span><span style="color: #339933;">,</span>
	    <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'wurst'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'client'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'irgendwo.de'</span> <span style="color: #666666; font-style: italic;">// &lt;-- Die Rettung</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delivery</span> 	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'smtp'</span><span style="color: #339933;">;</span>		
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/404/php/554-helo-command-rejected-sorry-localhost-is-local-not-remote/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SMPT 450 : Sender address rejected: Domain not found</title>
		<link>http://www.php-log.de/343/php/smpt-450-sender-address-rejected-domain-not-found</link>
		<comments>http://www.php-log.de/343/php/smpt-450-sender-address-rejected-domain-not-found#comments</comments>
		<pubDate>Fri, 05 Jun 2009 03:49:03 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SMTP]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=343</guid>
		<description><![CDATA[Diese kleine böse Falle hat mich gerade locker eine Stunde gekostet. Plötzlich sendet meine SMTP Klasse keine Mails mehr. Bekomme nur diese Fehlermeldung. Okay, wer lesen kann kommt sicher drauf was passiert ist, aber manchmal liest man einfach nicht sondern befragt die einschlägigen Suchmaschienen. Vergebens! Dabei ist der Fehler so offensichtlich. Ich habe versucht mit [...]]]></description>
			<content:encoded><![CDATA[<p>Diese kleine böse Falle hat mich gerade locker eine Stunde gekostet. Plötzlich sendet meine SMTP Klasse keine Mails mehr. Bekomme nur diese Fehlermeldung. Okay, wer lesen kann kommt sicher drauf was passiert ist, aber manchmal liest man einfach nicht sondern befragt die einschlägigen Suchmaschienen. Vergebens!<span id="more-343"></span></p>
<p>Dabei ist der Fehler so offensichtlich. Ich habe versucht mit einem From Header zu senden der dem SMTP Server nicht bekannt war. Konkret am Bespiel der Email Komponente von CakePHP sieht das so aus:</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;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">smtpOptions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'port'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">'timeout'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'host'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'smtp.deinedomain.de'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'hokus@deinedomain.de'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sachichnich'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delivery</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'smtp'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">to</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;sample@address.com&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">subject</span> <span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Dein Passwort '</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> env<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span> 	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'lost_password'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sendAs</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'both'</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// Hier passt die Domain home.com nicht zum SMTP Host...</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">replyTo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Ich &lt;hans@home.com&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Ich &lt;hans@home.com&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// ...deswegen dieser nette Fehler</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">smtpError</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># 450 : Sender address rejected: Domain not found
</span>
<span style="color: #666666; font-style: italic;">// So ist's richtig und die Mail wird verschickt</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">replyTo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Ich &lt;hans@deinedomain.de&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Ich &lt;hans@deinedomain.de&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/343/php/smpt-450-sender-address-rejected-domain-not-found/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Von CakePHP, Ajax Problemen und der Security Komponente</title>
		<link>http://www.php-log.de/128/php/von-cakephp-ajax-problemen-und-der-security-komponente</link>
		<comments>http://www.php-log.de/128/php/von-cakephp-ajax-problemen-und-der-security-komponente#comments</comments>
		<pubDate>Tue, 03 Feb 2009 23:52:00 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[PEAR]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=128</guid>
		<description><![CDATA[Wer die &#8220;Security&#8221; Komponente von CakePHP in seinen Projekte einsetzt, kann bei der Ajax-Entwicklung die ein oder andere fröhliche, kleine Überraschung erleben. Und zwar in Form eines 404 Errors. Oder zu Deutsch: &#8220;Ajax geht nicht&#8221;. Warum nicht? Weil die Security Komponente verschlüsselte Daten (Security Tokens) in die Session schreibt die, im Falle eines Ajax Requests, [...]]]></description>
			<content:encoded><![CDATA[<p>Wer die &#8220;Security&#8221; Komponente von CakePHP in seinen Projekte einsetzt, kann bei der Ajax-Entwicklung die ein oder andere fröhliche, kleine Überraschung erleben. Und zwar in Form eines 404 Errors. Oder zu Deutsch: &#8220;Ajax geht nicht&#8221;. Warum nicht? Weil die Security Komponente verschlüsselte Daten (Security Tokens) in die Session schreibt die, im Falle eines Ajax Requests, nicht validiert werden können. Da steht sich CakePHP irgendwie selbst im Weg, vermutet böse Dinge und gibt deshalb lieber einen verwirrenden 404 Not found.<span id="more-128"></span></p>
<blockquote><p>Am Rande bemerkt: Der Einsatz des Firfox Addons <a href="https://addons.mozilla.org/de/firefox/addon/1843" target="_blank">Firebug</a> ist für die Entwicklung von Ajax dringend zu empfehlen.</p></blockquote>
<p>Zum Glück bietet CakePHP, wie es sich für ein gutes Framework gehört, auch hier eine beglückend einfache Lösung an. Den blackHoleCallback der Komponente Security. Dieser behandelt das Auftreten von Sicherheitsverstößen, ist in der Lage den 404er zu unterbinden und lässt das Framework weiterlaufen. Mein Lösung sieht so aus.</p>
<ol>
<li>blackHoleCallback im beforeFilter des AppController definieren.</li>
<li>In der Callback-Methode prüfen ob es eine genehme AJAX Methode betrifft.</li>
<li>Wenn &#8220;Ja&#8221;, einfach return. Sobald der Callback definiert wurde ist er für alles verantworlich, inkl. Terminerung des Scripts etc.</li>
<li>Wenn &#8220;Nein&#8221;, exit() und ggfl. Logging und/oder andere Maßnahmen.</li>
</ol>
<p>In Code gegossen sieht das so aus:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> AppController <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>	
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$components</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Security'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> is_allowed_ajax_request<span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;users&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;auto_complete&quot;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'invalid request'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> beforeFilter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>		
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Security</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">blackHoleCallback</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;is_allowed_ajax_request&quot;</span><span style="color: #339933;">;</span>		
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/128/php/von-cakephp-ajax-problemen-und-der-security-komponente/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>E-Mail mit Anhang über PHP 4 versenden</title>
		<link>http://www.php-log.de/23/php/e-mail-mit-anhang-uber-php-4-versenden</link>
		<comments>http://www.php-log.de/23/php/e-mail-mit-anhang-uber-php-4-versenden#comments</comments>
		<pubDate>Tue, 27 Jan 2009 11:43:30 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[Mail]]></category>
		<category><![CDATA[PEAR]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Email]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=23</guid>
		<description><![CDATA[Immer wieder stößt man auf Server bzw. Webseiten die noch mit PHP 4 betrieben werden. Daran wird sich auch in absehbarer Zukunft nichts ändern. Wer also mal eben schnell was in so einer antiquierten Umgegebung erledigen möchte kann nicht auf moderne Frameworks setzten, da diese meist PHP 5 erfordern. Eines der bekanntesten Frameworks die PHP [...]]]></description>
			<content:encoded><![CDATA[<p>Immer wieder stößt man auf Server bzw. Webseiten die noch mit PHP 4 betrieben werden. Daran wird sich auch in absehbarer Zukunft nichts ändern. Wer also mal eben schnell was in so einer antiquierten Umgegebung erledigen möchte kann nicht auf moderne Frameworks setzten, da diese meist PHP 5 erfordern. Eines der bekanntesten Frameworks die PHP 5 unterstützen ist sicherlich <a href="http://pear.php.net/">PEAR</a>, das obwohl es zu &#8220;The PHP Group&#8221; gehört, eine vom Aussterben bedrohte Spezies ist. Wie auch immer, für alte Systeme sollte es dennoch nützlich sein. Sollte&#8230;</p>
<p><span id="more-23"></span>Für das Arbeiten mit PEAR haben die Amerikaner extra den Begriff &#8220;pain in the ass&#8221; geprägt (oder gab es den schon vorher und waren es gar die Engländer?). Mal fehlen Komponenten mal werden Klassen nicht gefunden, mal ist PEAR nicht auf dem Server installiert etc. pp&#8230;Ich denke jeder kennt das Dilemma, es ist nicht Fleisch und nicht Fisch.</p>
<p>Hier ist nun meine Lösung für das Versenden einer Mail mit Attachment und der Hilfe von PEAR. Es handelt sich um eine Zusammenstellung der benötigten PEAR Komponenten und einem Script das alles zusammenfügt. Die PEAR Scripte sind leicht modifiziert, ich musste einfach ein paar Pfade anpassen. Für Server bei denen der Versand über die native mail() Funktion von PHP nicht konfiguriert ist, was die absolute Ausnahme ist, habe ich SMTP Versand als Option mit eingebaut.</p>
<p><a href="http://www.php-log.de/wp-content/uploads/2009/01/pear-mail-with-attachments.zip"></a><a href="http://www.php-log.de/wp-content/uploads/2009/01/pear-mail-with-attachments.zip">PEAR Mailer mit Anhang</a></p>
<p>Hier nun das Demo Script für den Mailversand:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;display_errors&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FROM'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Ralf Kramer &lt;rk@belisar.de&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SUBJECT'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Happy Mail!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'USE_SMTP'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SMTP_HOST'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mail.mustersample.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SMTP_USER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'max@mustersample.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SMTP_PASSWORD'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'yoursecret'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'EMAIL_RECIPIENT'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'max@mustersample.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> send_mail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Pear/Mail.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// uncomment this line if php complainy about a missing nt_smtp class</span>
	<span style="color: #666666; font-style: italic;">#include_once (&quot;Pear/SMTP.php&quot;);
</span>
	<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Pear/Mail/mime.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'A happy little mail for you. Enjoy!'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'A happy little mail for you. Enjoy!'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$crlf</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$header</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'From'</span> <span style="color: #339933;">=&gt;</span> FROM<span style="color: #339933;">,</span> <span style="color: #0000ff;">'Subject'</span> <span style="color: #339933;">=&gt;</span> SUBJECT <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;sendme.txt&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$mime</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Mail_mime<span style="color: #009900;">&#40;</span><span style="color: #000088;">$crlf</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$mime</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTXTBody</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$mime</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setHTMLBody</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$mime</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttachment</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'text/plain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mime</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$header</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mime</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headers</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   	<span style="color: #000088;">$smtp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;host&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> SMTP_HOST<span style="color: #339933;">;</span>
    <span style="color: #000088;">$smtp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;port&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;25&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$smtp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;auth&quot;</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>
	<span style="color: #000088;">$smtp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;localhost&quot;</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;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$smtp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;timeout&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$smtp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> SMTP_USER<span style="color: #339933;">;</span>
    <span style="color: #000088;">$smtp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> SMTP_PASSWORD<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>USE_SMTP<span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$mail</span> <span style="color: #339933;">=&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #990000;">Mail</span><span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'smtp'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$smtp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
		<span style="color: #000088;">$mail</span> <span style="color: #339933;">=&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #990000;">Mail</span><span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mail'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span>EMAIL_RECIPIENT<span style="color: #339933;">,</span> <span style="color: #000088;">$header</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</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;">$res</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Mail send.&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
		debug<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Mail sending failed.'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$res</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> debug<span style="color: #009900;">&#40;</span><span style="color: #000088;">$msg</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Status: 400 Bad Request&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$msg</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
send_mail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/23/php/e-mail-mit-anhang-uber-php-4-versenden/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
