1<?php
2$to = $_POST['email'];
3$subject = "Email Subject";
4
5$message = 'Dear '.$_POST['name'].',<br>';
6$message .= "We welcome you to be part of family<br><br>";
7$message .= "Regards,<br>";
8
9// Always set content-type when sending HTML email
10$headers = "MIME-Version: 1.0" . "\r\n";
11$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
12
13// More headers
14$headers .= 'From: <enquiry@example.com>' . "\r\n";
15$headers .= 'Cc: myboss@example.com' . "\r\n";
16
17mail($to,$subject,$message,$headers);
18?>
1<?php
2 mail("recipient@example.com",
3 "This is the message subject",
4 "This is the message body",
5 "From: sender@example.com" . "\r\n" . "Content-Type: text/plain; charset=utf-8",
6 "-fsender@example.com");
7?>
1<?php
2use PHPMailer\PHPMailer\PHPMailer;
3use PHPMailer\PHPMailer\Exception;
4
5require_once "vendor/autoload.php";
6
7//PHPMailer Object
8$mail = new PHPMailer(true); //Argument true in constructor enables exceptions
9
10//From email address and name
11$mail->From = "from@yourdomain.com";
12$mail->FromName = "Full Name";
13
14//To address and name
15$mail->addAddress("recepient1@example.com", "Recepient Name");
16$mail->addAddress("recepient1@example.com"); //Recipient name is optional
17
18//Address to which recipient will reply
19$mail->addReplyTo("reply@yourdomain.com", "Reply");
20
21//CC and BCC
22$mail->addCC("cc@example.com");
23$mail->addBCC("bcc@example.com");
24
25//Send HTML or Plain Text email
26$mail->isHTML(true);
27
28$mail->Subject = "Subject Text";
29$mail->Body = "<i>Mail body in HTML</i>";
30$mail->AltBody = "This is the plain text version of the email content";
31
32try {
33 $mail->send();
34 echo "Message has been sent successfully";
35} catch (Exception $e) {
36 echo "Mailer Error: " . $mail->ErrorInfo;
37}
38