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// use this library -> https://github.com/PHPMailer/PHPMailer
2
3<?php
4use PHPMailer\PHPMailer\PHPMailer;
5use PHPMailer\PHPMailer\SMTP;
6use PHPMailer\PHPMailer\Exception;
7function sendEmail(){
8 require 'phpmailer/vendor/autoload.php';
9
10 //Create an instance; passing `true` enables exceptions
11 $mail = new PHPMailer(true);
12 $mail->CharSet = 'UTF-8';
13 try {
14 $receiver = 'test@gmail.com';
15 $name = 'Name';
16
17 //Server settings
18 $mail->SMTPDebug = 1; //Enable verbose debug output
19 $mail->isSMTP(); //Send using SMTP
20 $mail->Host = 'tls://smtp.gmail.com'; //Set the SMTP server to send through
21 $mail->SMTPAuth = true; //Enable SMTP authentication
22 $mail->Username = 'username@gmail.com'; //SMTP username
23 $mail->Password = 'PASSWORD'; //SMTP password
24 $mail->SMTPSecure = tls; //Enable implicit TLS encryption
25 $mail->Port = 587; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
26
27 //Recipients
28 $mail->From = 'test@gmail.com';
29 $mail->setFrom('test@gmail.com', 'Name');
30 $mail->addAddress($receiver, $name); //Add a recipient
31
32 //Content
33 $mail->isHTML(true); //Set email format to HTML
34 $mail->Subject = 'Subject';
35 $mail->Body = 'Body';
36
37 $mail->send();
38 echo 'Message has been sent';
39 } catch (Exception $e) {
40 echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
41 }
42}
43?>
1<?php
2//Import PHPMailer classes into the global namespace
3//These must be at the top of your script, not inside a function
4use PHPMailer\PHPMailer\PHPMailer;
5use PHPMailer\PHPMailer\SMTP;
6use PHPMailer\PHPMailer\Exception;
7
8//Load Composer's autoloader
9require 'vendor/autoload.php';
10
11//Instantiation and passing `true` enables exceptions
12$mail = new PHPMailer(true);
13
14try {
15 //Server settings
16 $mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
17 $mail->isSMTP(); //Send using SMTP
18 $mail->Host = 'smtp.example.com'; //Set the SMTP server to send through
19 $mail->SMTPAuth = true; //Enable SMTP authentication
20 $mail->Username = 'user@example.com'; //SMTP username
21 $mail->Password = 'secret'; //SMTP password
22 $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
23 $mail->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
24
25 //Recipients
26 $mail->setFrom('from@example.com', 'Mailer');
27 $mail->addAddress('joe@example.net', 'Joe User'); //Add a recipient
28 $mail->addAddress('ellen@example.com'); //Name is optional
29 $mail->addReplyTo('info@example.com', 'Information');
30 $mail->addCC('cc@example.com');
31 $mail->addBCC('bcc@example.com');
32
33 //Attachments
34 $mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
35 $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
36
37 //Content
38 $mail->isHTML(true); //Set email format to HTML
39 $mail->Subject = 'Here is the subject';
40 $mail->Body = 'This is the HTML message body <b>in bold!</b>';
41 $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
42
43 $mail->send();
44 echo 'Message has been sent';
45} catch (Exception $e) {
46 echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
47}
1<?php
2// Multiple recipients
3$to = 'johny@example.com, sally@example.com'; // note the comma
4
5// Subject
6$subject = 'Birthday Reminders for August';
7
8// Message
9$message = '
10<html>
11<head>
12 <title>Birthday Reminders for August</title>
13</head>
14<body>
15 <p>Here are the birthdays upcoming in August!</p>
16 <table>
17 <tr>
18 <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
19 </tr>
20 <tr>
21 <td>Johny</td><td>10th</td><td>August</td><td>1970</td>
22 </tr>
23 <tr>
24 <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
25 </tr>
26 </table>
27</body>
28</html>
29';
30
31// To send HTML mail, the Content-type header must be set
32$headers[] = 'MIME-Version: 1.0';
33$headers[] = 'Content-type: text/html; charset=iso-8859-1';
34
35// Additional headers
36$headers[] = 'To: Mary <mary@example.com>, Kelly <kelly@example.com>';
37$headers[] = 'From: Birthday Reminder <birthday@example.com>';
38$headers[] = 'Cc: birthdayarchive@example.com';
39$headers[] = 'Bcc: birthdaycheck@example.com';
40
41// Mail it
42if(mail($to, $subject, $message, implode("\r\n", $headers))){
43 echo "success";
44}else{
45 echo "Echec send email";
46}
47;
48?>
1$message = '
2<html>
3<head>
4 <title>Review Request Reminder</title>
5</head>
6<body>
7 <p>Here are the cases requiring your review in December:</p>
8 <table>
9 <tr>
10 <th>Case title</th><th>Category</th><th>Status</th><th>Due date</th>
11 </tr>
12 <tr>
13 <td>Case 1</td><td>Development</td><td>pending</td><td>Dec-20</td>
14 </tr>
15 <tr>
16 <td>Case 1</td><td>DevOps</td><td>pending</td><td>Dec-21</td>
17 </tr>
18 </table>
19</body>
20</html>
21';