Wednesday, August 17, 2022

Membuat Email dengan PHP


Berikut adalah contoh membuat email dengan PHP :

1. Buat class  mail, dengan nama : 

Mailer.class.php

<?php
/*  Class name  : Mailer  Description : Class untuk mengirim Email 
*/
class Mailer {
// declare private attributes
private $from;
private $subject;
private $to = array();
private $cc = array();
private $bcc = array();
private $message;
public $error;
// Class constructor
public function __construct($from, $to, $subject, $message) {
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->message = $message;
}
// accessor functions
public function __set($name, $value) {
        $this->$name = $value;
    }
    public function __get($name) {
        return $this->$name;
    }
 
public function send_mail() {
if (!empty($this->to) && count($this->to) > 0) {
$destination = implode (',',$this->to);
}
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (!empty($this->to)) {
$headers .= 'From: '. $this->from . "\r\n";
}
if (!empty($this->cc) && count($this->cc) > 0) {
$headers .= 'Cc: ';
$headers .= implode (',',$this->cc);
$headers .= "\r\n";
}
if (!empty($this->bcc) && count($this->bcc) > 0) {
$headers .= 'Bcc: ';
$headers .= implode (',',$this->bcc);
$headers .= "\r\n";
}
 
if(mail($destination, $this->subject, $this->message, $headers)) {
return true;
} else {
$this->error = 'Server mail error.';
return false;
}
}
}
?>



2. Buat form untuk send email dengan nama :

send_mail.php

<html>
<head><title>Kirim Email dengan PHP</title></head>
<body>
<h1>Kirim Email</h1>
<form action="" method="post">
<table width="100%">
<tr>
<td width="150">Pengirim </td>
<td><input type="text" name="pengirim" size="40"/></td>
</tr>
<tr>
<td>Penerima  </td>
<td><input type="text" name="penerima" size="40"/></td>
</tr>
<tr>
<td>Judul: </td>
<td><input type="text" name="judul" size="40"/></td>
</tr>
<tr>
<td>Pesan: </td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2"><textarea cols="58" rows="10" name="pesan"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Send" value="Send"/><input type="reset" name="reset" value="Cancel"/></td>
</tr>
</table>
</form>
 
<?php
include "Mailer.class.php";
if (isset($_POST['Send'])) {
$pengirim = $_POST['pengirim'];
$penerima = $_POST['penerima'];
$judul    = $_POST['judul'];
$pesan    = $_POST['pesan'];
 
if ($pengirim=='') {
die("Pengirim harus diisi");
}
 
$mailer = new Mailer($pengirim,$penerima, $judul, $pesan);
$mailer->send_mail();
}
?>
</body>
</html>

Tampilan Layout :


Isikan data pengiri,, penerima, judul, dan pesan, lalu klik Send, maka email akan dikirimkan ke penerima

Memunculkan Simbol & Emoji Pada OS Mac

  Memunculkan Simbol & Emoji  1. Buka aplikasi Pages / Notes pada Macbook. 2. Klik pada Menubar Edit --> Pilih Emoji and Symbols a...