<?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; Email</title>
	<atom:link href="http://www.php-log.de/tags/email/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>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>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>
