simple way to send email php code example
Example 1: smtp in php mail function
<?php
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT);
require_once "Mail.php";
$host = "ssl://smtp.dreamhost.com";
$username = "[email protected]";
$password = "your email password";
$port = "465";
$to = "[email protected]";
$email_from = "[email protected]";
$email_subject = "Subject Line Here:" ;
$email_body = "whatever you like" ;
$email_address = "[email protected]";
$headers = array ('From' => $email_from, 'To' => $to, 'Subject' => $email_subject, 'Reply-To' => $email_address);
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $email_body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
Example 2: read an email with php
<?php
class Email_reader {
public $conn;
private $inbox;
private $msg_cnt;
private $server = 'yourserver.com';
private $user = '[email protected]';
private $pass = 'yourpassword';
private $port = 143;
function __construct() {
$this->connect();
$this->inbox();
}
function close() {
$this->inbox = array();
$this->msg_cnt = 0;
imap_close($this->conn);
}
function connect() {
$this->conn = imap_open('{'.$this->server.'/notls}', $this->user, $this->pass);
}
function move($msg_index, $folder='INBOX.Processed') {
imap_mail_move($this->conn, $msg_index, $folder);
imap_expunge($this->conn);
$this->inbox();
}
function get($msg_index=NULL) {
if (count($this->inbox) <= 0) {
return array();
}
elseif ( ! is_null($msg_index) && isset($this->inbox[$msg_index])) {
return $this->inbox[$msg_index];
}
return $this->inbox[0];
}
function inbox() {
$this->msg_cnt = imap_num_msg($this->conn);
$in = array();
for($i = 1; $i <= $this->msg_cnt; $i++) {
$in[] = array(
'index' => $i,
'header' => imap_headerinfo($this->conn, $i),
'body' => imap_body($this->conn, $i),
'structure' => imap_fetchstructure($this->conn, $i)
);
}
$this->inbox = $in;
}
}
?>
A fair amount of this is