Tutorial PHP

RUMAH PHP Pengenalan PHP Instal PHP Sintaks PHP Komentar PHP Variabel PHP PHP Gema / Cetak Tipe Data PHP String PHP Nomor PHP PHP Matematika Konstanta PHP Operator PHP PHP Jika...Lain...Elseif Beralih PHP PHP Loop Fungsi PHP Array PHP PHP Superglobal PHP RegEx

Formulir PHP

Penanganan Formulir PHP Validasi Formulir PHP Diperlukan Formulir PHP URL/Email Formulir PHP Formulir PHP Lengkap

PHP Lanjutan

Tanggal dan Waktu PHP PHP Termasuk Penanganan File PHP File PHP Buka/Baca Membuat/Menulis File PHP Unggah File PHP Cookie PHP Sesi PHP Filter PHP Filter PHP Tingkat Lanjut Fungsi Panggilan Balik PHP PHP JSON Pengecualian PHP

PHP OOP

PHP Apa itu OOP Kelas/Objek PHP Konstruktor PHP Penghancur PHP Pengubah Akses PHP Warisan PHP Konstanta PHP Kelas Abstrak PHP Antarmuka PHP Ciri-ciri PHP Metode Statis PHP Properti Statis PHP Ruang Nama PHP PHP Iterable

Database MySQL

Database MySQL Koneksi MySQL MySQL Buat DB MySQL Buat Tabel MySQL Sisipkan Data MySQL Dapatkan ID Terakhir MySQL Sisipkan Beberapa MySQL Disiapkan MySQL Pilih Data MySQL Dimana MySQL Dipesan Oleh MySQL Hapus Data Data Pembaruan MySQL Data Batas MySQL

PHP XML

PHP XML Parser PHP SimpleXML Parser PHP SimpleXML - Dapatkan PHP XML Ekspat PHP XML DOM

PHP - AJAX

Pengenalan AJAX AJAX PHP Basis Data AJAX AJAX XML Pencarian Langsung AJAX Jajak Pendapat AJAX

Contoh PHP

Contoh PHP Kompilator PHP Kuis PHP Latihan PHP Sertifikat PHP

Referensi PHP

Ikhtisar PHP Array PHP Kalender PHP Tanggal PHP Direktori PHP Kesalahan PHP Pengecualian PHP Sistem File PHP Filter PHP PHP FTP PHP JSON Kata Kunci PHP PHP Libxml Surat PHP PHP Matematika PHP Lain-lain PHP MySQLi Jaringan PHP Kontrol Keluaran PHP PHP RegEx PHP SimpleXML Aliran PHP String PHP Penanganan Variabel PHP PHP XML Parser PHP Zip Zona Waktu PHP

PHP mail() Fungsi

Referensi Surat PHP

Contoh

Kirim email sederhana:

<?php
// the message
$msg = "First line of text\nSecond line of text";

// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);

// send email
mail("[email protected]","My subject",$msg);
?>

Definisi dan Penggunaan

Fungsi mail() memungkinkan Anda mengirim email langsung dari skrip.

Sintaksis

mail(to,subject,message,headers,parameters);

Nilai Parameter

Parameter Description
to Required. Specifies the receiver / receivers of the email
subject Required. Specifies the subject of the email. Note: This parameter cannot contain any newline characters
message Required. Defines the message to be sent. Each line should be separated with a LF (\n). Lines should not exceed 70 characters.

Windows note: If a full stop is found on the beginning of a line in the message, it might be removed. To solve this problem, replace the full stop with a double dot:
<?php
$txt = str_replace("\n.", "\n..", $txt);
?>

headers Optional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n).

Note: When sending an email, it must contain a From header. This can be set with this parameter or in the php.ini file.

parameters Optional. Specifies an additional parameter to the sendmail program (the one defined in the sendmail_path configuration setting). (i.e. this can be used to set the envelope sender address when using sendmail with the -f sendmail option)


Detail Teknis

Nilai Kembali: Mengembalikan nilai hash dari parameter alamat , atau FALSE pada kegagalan. Catatan: Perlu diingat bahwa meskipun email diterima untuk pengiriman, BUKAN berarti email tersebut benar-benar terkirim dan diterima!
Versi PHP: 4+
Log Perubahan PHP: PHP 7.2: Parameter header juga menerima array
PHP 5.4: Menambahkan perlindungan injeksi header untuk parameter header .
PHP 4.3.0: (Khusus Windows) Semua header khusus (seperti Dari, Cc, Bcc, dan Tanggal) didukung, dan tidak peka huruf besar/kecil.
PHP 4.2.3: Parameter parameter dinonaktifkan dalam mode aman
PHP 4.0.5: Parameter parameter telah ditambahkan

Lebih Banyak Contoh

Kirim email dengan tajuk tambahan:

<?php
$to = "[email protected]";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: [email protected]" . "\r\n" .
"CC: [email protected]";

mail($to,$subject,$txt,$headers);
?>

Kirim email HTML:

<?php
$to = "[email protected], [email protected]";
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";

mail($to,$subject,$message,$headers);
?>

Referensi Surat PHP Lengkap