Sent mail php
In PHP, you can send an email using the mail()
function. Here is a basic example:
<?php
$to = '[email protected]';
$subject = 'Test email';
$message = 'This is a test email sent using PHP';
$headers = 'From: [email protected]'. "\r\n".
'Reply-To: [email protected]'. "\r\n".
'MIME-Version: 1.0'. "\r\n".
'Content-Type: text/plain; charset=UTF-8';
mail($to, $subject, $message, $headers);
?>
This code sends an email to the recipient at [email protected]
with the subject "Test email" and the message "This is a test email sent using PHP". The email is sent from the sender at [email protected]
.
You can also use the PHPMailer
library, which is a popular and powerful email sending library for PHP. Here is an example:
<?php
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'password';
$mail->setFrom('[email protected]', 'Sender Name');
$mail->addAddress('[email protected]', 'Recipient Name');
$mail->Subject = 'Test email';
$mail->Body = 'This is a test email sent using PHPMailer';
if (!$mail->send()) {
echo 'Error sending email: '. $mail->ErrorInfo;
} else {
echo 'Email sent successfully!';
}
?>
This code sends an email using the PHPMailer
library, which is configured to use a SMTP server at smtp.example.com
. The email is sent from the sender at [email protected]
to the recipient at [email protected]
.
Note that you need to install the PHPMailer
library and configure it according to your email server settings.