send html email with php code example
Example 1: how to send email with php
<?php
var Name = $_POST('name');
var Email = $_POST('email');
var Number = $_POST('number');
$to_email = 'Your E-mail';
$subject = 'The Subject of the message';
$message = 'Name'.$name. "email" .$email. "number:" .$number.".";
$headers = 'From: noreply @ company . com';
mail($to_email,$subject,$message,$headers);
?>
Example 2: html php email
$mailtext = '<html>
<head>
<title>HTML-E-Mail mit PHP erstellen</title>
</head>
<body>
...
</body>
</html>
';
$empfaenger = "[email protected]";
$absender = "[email protected]";
$betreff = "Mail-Test - HTML-E-Mail mit PHP erstellen";
$antwortan = "[email protected]";
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset=utf-8\r\n";
$header .= "From: $absender\r\n";
$header .= "Reply-To: $antwortan\r\n";
$header .= "X-Mailer: PHP ". phpversion();
mail( $empfaenger,
$betreff,
$mailtext,
$header);
echo "Mail wurde gesendet!";
Example 3: 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