PHP MailThe example below shows how to send email. $mailadd="test@mysite.com"; $mesage="This is a test of using PHP to send email."; $headers .= "From: <" . $mailadd . ">\n"; $headers .= "X-Sender: <" . $mailadd . ">\n"; $headers .= "X-Mailer: PHP\n"; // mailer $headers .= "Return-Path: <" . $mailadd . ">\n"; // Return path for errors $subject="Test of PHP Mail sending"; mail($email, $subject, $mesage, $headers); The example below shows how to read email from a mailbox and check the contents of the subject line. In this case, someone has sent an email to the inbox that we are reading. If the email contains the string "update?str_ID" the code will determine this and get the ID number to be updated. It uses several string functions to do this, so this example is a good example of using string functions.
1 <?php
2 $mailadd="submissions@mysite.com
3 $mailpass="password";
4 $mailhand=imap_open("{localhost/pop3:110}INBOX", $mailadd, $mailpass);
5 if ($mailhand)
6 {
7 $msgqty=imap_num_msg($mailhand); //get number of mail messages
8 for ($i2=1; $i2<=$msgqty; $i2++) //Read each message
9 {
10 $header=imap_header($mailhand,$i2); //Get the message header
11 echo $header->subject . "<br>";
12 $hd=strtolower($header->subject); //Convert to lower case characters
13 if ($opstr=strstr($hd,"update?")) //See if header contained the string "update?"
14 {
15 $tok = strtok ($opstr," ");
16 if ($opstr=strchr($tok,"?")) //Returns the string from the "?" until the end
17 {
18 $tok=substr($opstr,1); //Strips the "?", should now have id
19 $id=intval($tok); //Converts the ID number to an integer
20 $newflag=1;
21 $query1="update " . $mainsection . " set update1=" . $newflag . " where id = " . $id;
22 mysql_db_query($dbname, $query1) or die("Failed Query of " . $query1);
23 imap_delete($mailhand,$i2);
24 echo $id . " marked to be updated.";
25 }
26 }
27 }
28 imap_expunge($mailhand); //delete marked messages
29 imap_close($mailhand); //113
30 }
31 else
32 {
33 echo "can't connect: " . imap_last_error();
34 }
35 ?>
The list below is an explanation of the lines: |