Note that there are some explanatory texts on larger screens.

plurals
  1. POworking with Email headers - PHP
    text
    copied!<p>I'm piping my incoming emails to a handler.php. I can pipe it successfully and it's working, but when it gets to getting out the variables from mail header, for example the "Subject", or "To", or the "message body", I'm experiencing some problems. Here is the code I got from <a href="http://www.phpshare.org/articles/Piping-Incoming-Mail-with-PHP" rel="nofollow">here</a></p> <p>here is the code:</p> <pre><code> &lt;?php //Assumes $email contains the contents of the e-mail //When the script is done, $subject, $to, $message, and $from all contain appropriate values //Parse "subject" $subject1 = explode ("\nSubject: ", $email); $subject2 = explode ("\n", $subject1[1]); $subject = $subject2[0]; //Parse "to" $to1 = explode ("\nTo: ", $email); $to2 = explode ("\n", $to1[1]); $to = str_replace ('&gt;', '', str_replace('&lt;', '', $to2[0])); $message1 = explode ("\n\n", $email); $start = count ($message1) - 3; if ($start &lt; 1) { $start = 1; } //Parse "message" $message2 = explode ("\n\n", $message1[$start]); $message = $message2[0]; //Parse "from" $from1 = explode ("\nFrom: ", $email); $from2 = explode ("\n", $from1[1]); if(strpos ($from2[0], '&lt;') !== false) { $from3 = explode ('&lt;', $from2[0]); $from4 = explode ('&gt;', $from3[1]); $from = $from4[0]; } else { $from = $from2[0]; } ?&gt; </code></pre> <p>For Gmail emails, it gets the subject, from, to, and the message body fine, but it's not working for the incoming emails from Yahoo.</p> <p>Is there any universal php class which is compatible with all famous email service providers? what if someone sends an email from RoundCube, or another email sender? How I could successfully detect the variables?</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload