mail php send code example
Example 1: php mail
<?php
$to = $_POST['email'];
$subject = "Email Subject";
$message = 'Dear '.$_POST['name'].',<br>';
$message .= "We welcome you to be part of family<br><br>";
$message .= "Regards,<br>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
mail($to,$subject,$message,$headers);
?>
Example 2: how to send email with php
<?php
var Name = $_POST('name');
var Email = $_POST('email');
var Number = $_POST('number');
$to_email = 'Your E-mail';
$subject = 'The Subject of the message';
$message = 'Name'.$name. "email" .$email. "number:" .$number.".";
$headers = 'From: noreply @ company . com';
mail($to_email,$subject,$message,$headers);
?>
Example 3: PHP MAILER
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once "vendor/autoload.php";
$mail = new PHPMailer(true);
$mail->From = "[email protected]";
$mail->FromName = "Full Name";
$mail->addAddress("[email protected]", "Recepient Name");
$mail->addAddress("[email protected]");
$mail->addReplyTo("[email protected]", "Reply");
$mail->addCC("[email protected]");
$mail->addBCC("[email protected]");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
try {
$mail->send();
echo "Message has been sent successfully";
} catch (Exception $e) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
Example 4: mail php send
emailsend.php