PHP Mengizinkan kita untuk mengirim email dari script
PHP mail() function di gunakan untuk mengirim pesan/email
Syntax : mail(to,subject,message,headers,parameters)
Parameter | Description |
to | Required. Menandakan Penerima |
subject | Required. Menandakan Judul Pesan Note: Parameter ini tidak bisa mengandung bari baru atau paragraf |
message | Required. Mendefinisikan pesan yang akan di kirim |
headers | Optional. Menspesifikan CC / BCC |
parameters | Optional. Menspesifikasikan Additional parameter |
PHP Simple E-Mail
Langkah mudah mengirim email dengan php
Pertama deklarasikan variable
($to, $subject, $message, $from, $headers), kemudian gunakan function mail() untuk mengirim email :
<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
PHP Mail Form
Kalau yang di atas kan cara mengirim email dengan cara manual , kalau yang ini dengan mengunakan form :
<html>
<body>
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("someone@example.com", $subject,
$message, "From:" . $email);
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>
</body>
</html>
Note: This is the simplest way to send e-mail, but it is not secure. In the next chapter of this tutorial you can read more about vulnerabilities in e-mail scripts, and how to validate user input to make it more secure.
PHP Mail Reference
For more information about the PHP mail() function, visit our PHP Mail Reference.
Read more…