Peralatan yang diperlukan :
1. PHP 5.3
2. Integrated Development Environtment (NetBeans, Dreamweaver, dll)
Email sudah bukan sesuatu hal yang aneh lagi saat ini, hampir setiap website biasanya membutuhkan fitur email ini. Jika Anda menggunakan PHP, bagaimana cara mengirim email di PHP? Mudah saja caranya…
Pertama kita buat dulu sebuah kelas MailSender, hal ini dilakukan agar nanti kelas ini dapat digunakan lagi
php
/**
* Description of MailSender
*
* @author Yulius Alghifarrie
*/
class MailSender {
private $from;
private $to;
private $subject;
private $message;
public function get_subject() {
return $this->subject;
}
public function set_subject($subject) {
$this->subject = $subject;
}
public function get_from() {
return $this->from;
}
public function set_from($from) {
$this->from = $from;
}
public function get_to() {
return $this->to;
}
public function set_to($to) {
$this->to = $to;
}
public function get_message() {
return $this->message;
}
public function set_message($message) {
$this->message = $message;
}
public function send() {
$headers = "From: $this->from" . "\r\n" .
"Reply-To: $this->from" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
mail($this->to, $this->subject, $this->message, $headers);
}
}
?>
Setelah itu coba buat sebuah halaman untuk mengirim email tersebut
set_from($_POST['from']);
$sender->set_to($_POST['to']);
$sender->set_subject($_POST['subject']);
$sender->set_message($_POST['message']);
// send email
$sender->send();
}
?>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
title>Send Email/title>
/head>
body>
form action="index.php" method="post">
table>
tr> td>From :/td> td>input type="text" name="from"/>/td> /tr>
tr> td>To :/td> td>input type="text" name="to"/>/td> /tr>
tr> td>Subject :/td> td>input type="text" name="subject"/>/td> /tr>
tr> td>Message :/td> td>
textarea name="message" cols="20" rows="5">
/td> /tr>
tr> td>/td> td>input type="submit" name="send" value="Send"/>/td> /tr>
/table>
/form>
/body>
/html>"
selamat mencoba… :D
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment