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
3error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT);
4
5require_once "Mail.php";
6
7$host = "ssl://smtp.dreamhost.com";
8$username = "youremail@example.com";
9$password = "your email password";
10$port = "465";
11$to = "address_form_will_send_TO@example.com";
12$email_from = "youremail@example.com";
13$email_subject = "Subject Line Here:" ;
14$email_body = "whatever you like" ;
15$email_address = "reply-to@example.com";
16
17$headers = array ('From' => $email_from, 'To' => $to, 'Subject' => $email_subject, 'Reply-To' => $email_address);
18$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
19$mail = $smtp->send($to, $headers, $email_body);
20
21if (PEAR::isError($mail)) {
22echo("<p>" . $mail->getMessage() . "</p>");
23} else {
24echo("<p>Message successfully sent!</p>");
25}
26?>
27
1mail ( string $to , string $subject , string $message [, mixed $additional_headers [, string $additional_parameters ]] ) : bool
1
2I migrated an application to a platform without a local transport agent (MTA). I did not want to configure an MTA, so I wrote this xxmail function to replace mail() with calls to a remote SMTP server. Hopefully it is of some use.
3
4function xxmail($to, $subject, $body, $headers)
5{
6 $smtp = stream_socket_client('tcp://smtp.yourmail.com:25', $eno, $estr, 30);
7
8 $B = 8192;
9 $c = "\r\n";
10 $s = 'myapp@someserver.com';
11
12 fwrite($smtp, 'helo ' . $_ENV['HOSTNAME'] . $c);
13 $junk = fgets($smtp, $B);
14
15 // Envelope
16 fwrite($smtp, 'mail from: ' . $s . $c);
17 $junk = fgets($smtp, $B);
18 fwrite($smtp, 'rcpt to: ' . $to . $c);
19 $junk = fgets($smtp, $B);
20 fwrite($smtp, 'data' . $c);
21 $junk = fgets($smtp, $B);
22
23 // Header
24 fwrite($smtp, 'To: ' . $to . $c);
25 if(strlen($subject)) fwrite($smtp, 'Subject: ' . $subject . $c);
26 if(strlen($headers)) fwrite($smtp, $headers); // Must be \r\n (delimited)
27 fwrite($smtp, $headers . $c);
28
29 // Body
30 if(strlen($body)) fwrite($smtp, $body . $c);
31 fwrite($smtp, $c . '.' . $c);
32 $junk = fgets($smtp, $B);
33
34 // Close
35 fwrite($smtp, 'quit' . $c);
36 $junk = fgets($smtp, $B);
37 fclose($smtp);
38}
39