1<?php
2//Modify it for your project
3class Email_reader {
4
5 // imap server connection
6 public $conn;
7
8 // inbox storage and inbox message count
9 private $inbox;
10 private $msg_cnt;
11
12 // email login credentials
13 private $server = 'yourserver.com';
14 private $user = 'email@yourserver.com';
15 private $pass = 'yourpassword';
16 private $port = 143; // adjust according to server settings
17
18 // connect to the server and get the inbox emails
19 function __construct() {
20 $this->connect();
21 $this->inbox();
22 }
23
24 // close the server connection
25 function close() {
26 $this->inbox = array();
27 $this->msg_cnt = 0;
28
29 imap_close($this->conn);
30 }
31
32 // open the server connection
33 // the imap_open function parameters will need to be changed for the particular server
34 // these are laid out to connect to a Dreamhost IMAP server
35 function connect() {
36 $this->conn = imap_open('{'.$this->server.'/notls}', $this->user, $this->pass);
37 }
38
39 // move the message to a new folder
40 function move($msg_index, $folder='INBOX.Processed') {
41 // move on server
42 imap_mail_move($this->conn, $msg_index, $folder);
43 imap_expunge($this->conn);
44
45 // re-read the inbox
46 $this->inbox();
47 }
48
49 // get a specific message (1 = first email, 2 = second email, etc.)
50 function get($msg_index=NULL) {
51 if (count($this->inbox) <= 0) {
52 return array();
53 }
54 elseif ( ! is_null($msg_index) && isset($this->inbox[$msg_index])) {
55 return $this->inbox[$msg_index];
56 }
57
58 return $this->inbox[0];
59 }
60
61 // read the inbox
62 function inbox() {
63 $this->msg_cnt = imap_num_msg($this->conn);
64
65 $in = array();
66 for($i = 1; $i <= $this->msg_cnt; $i++) {
67 $in[] = array(
68 'index' => $i,
69 'header' => imap_headerinfo($this->conn, $i),
70 'body' => imap_body($this->conn, $i),
71 'structure' => imap_fetchstructure($this->conn, $i)
72 );
73 }
74
75 $this->inbox = $in;
76 }
77
78}
79
80?>
81A fair amount of this is
1$mailtext = '<html>
2<head>
3 <title>HTML-E-Mail mit PHP erstellen</title>
4</head>
5
6<body>
7...
8</body>
9</html>
10';
11
12$empfaenger = "du@example.com"; // Mailadresse
13$absender = "ich@example.com";
14$betreff = "Mail-Test - HTML-E-Mail mit PHP erstellen";
15$antwortan = "ICH@example.com";
16
17$header = "MIME-Version: 1.0\r\n";
18$header .= "Content-type: text/html; charset=utf-8\r\n";
19
20$header .= "From: $absender\r\n";
21$header .= "Reply-To: $antwortan\r\n";
22// $header .= "Cc: $cc\r\n"; // falls an CC gesendet werden soll
23$header .= "X-Mailer: PHP ". phpversion();
24
25mail( $empfaenger,
26 $betreff,
27 $mailtext,
28 $header);
29
30echo "Mail wurde gesendet!";
1<form enctype="multipart/form-data" method="POST" action="">
2 <label>Your Name <input type="text" name="sender_name" /> </label>
3 <label>Your Email <input type="email" name="sender_email" /> </label>
4 <label>Subject <input type="text" name="subject" /> </label>
5 <label>Message <textarea name="message"></textarea> </label>
6 <label>Attachment <input type="file" name="attachment" /></label>
7 <label><input type="submit" name="button" value="Submit" /></label>
8</form>
9