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 
2if(isset($_POST['submit'])){
3    $to = "email@example.com"; // this is your Email address
4    $from = $_POST['email']; // this is the sender's Email address
5    $first_name = $_POST['first_name'];
6    $last_name = $_POST['last_name'];
7    $subject = "Form submission";
8    $subject2 = "Copy of your form submission";
9    $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
10    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
11
12    $headers = "From:" . $from;
13    $headers2 = "From:" . $to;
14    mail($to,$subject,$message,$headers);
15    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
16    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
17    // You can also use header('Location: thank_you.php'); to redirect to another page.
18    }
19?>
20
21<!DOCTYPE html>
22<head>
23<title>Form submission</title>
24</head>
25<body>
26
27<form action="" method="post">
28First Name: <input type="text" name="first_name"><br>
29Last Name: <input type="text" name="last_name"><br>
30Email: <input type="text" name="email"><br>
31Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
32<input type="submit" name="submit" value="Submit">
33</form>
34
35</body>
36</html> 1    $filename = 'myfile';
2    $path = 'your path goes here';
3    $file = $path . "/" . $filename;
4
5    $mailto = 'mail@mail.com';
6    $subject = 'Subject';
7    $message = 'My message';
8
9    $content = file_get_contents($file);
10    $content = chunk_split(base64_encode($content));
11
12    // a random hash will be necessary to send mixed content
13    $separator = md5(time());
14
15    // carriage return type (RFC)
16    $eol = "\r\n";
17
18    // main header (multipart mandatory)
19    $headers = "From: name <test@test.com>" . $eol;
20    $headers .= "MIME-Version: 1.0" . $eol;
21    $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
22    $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
23    $headers .= "This is a MIME encoded message." . $eol;
24
25    // message
26    $body = "--" . $separator . $eol;
27    $body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
28    $body .= "Content-Transfer-Encoding: 8bit" . $eol;
29    $body .= $message . $eol;
30
31    // attachment
32    $body .= "--" . $separator . $eol;
33    $body .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol;
34    $body .= "Content-Transfer-Encoding: base64" . $eol;
35    $body .= "Content-Disposition: attachment" . $eol;
36    $body .= $content . $eol;
37    $body .= "--" . $separator . "--";
38
39    //SEND Mail
40    if (mail($mailto, $subject, $body, $headers)) {
41        echo "mail send ... OK"; // or use booleans here
42    } else {
43        echo "mail send ... ERROR!";
44        print_r( error_get_last() );
45    }
461<?php
2$to      = 'nobody@example.com';
3$subject = 'the subject';
4$message = 'hello';
5$headers = 'From: Jack Sparrow <jsparrow@blackpearl.com>' . PHP_EOL .
6    'Reply-To: Jack Sparrow <jsparrow@blackpearl.com>' . PHP_EOL .
7    'X-Mailer: PHP/' . phpversion();
8
9mail($to, $subject, $message, $headers);
10?>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// 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?>