note 32650 deleted from function.mail by pollita
| From: | pollita@php.net | Date: | Tue, 03 Jun 2003 19:59:39 +0000 |
| Subject: | note 32650 deleted from function.mail by pollita | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-49656@lists.php.net to get a copy of this message | ||
Note Submitter: tiele@skynet.be
----
If you can't use the mail() function to send an email or if you wish to build up the complete
mail from scratch, you can use fsockopen. Here's how:
$smtp = fsockopen("localhost", "25"); // Open a connection to the SMTP server
(25 = standard smtp port)
fwrite($smtp, "HELO localhost\r\n"); // Identify yourself to the server
fwrite($smtp, "MAIL FROM: <my.email@job.com>\r\n"); // Sender
fwrite($smtp, "RCPT TO: <to.whom@other.com>\r\n"); // Reciever
fwrite($smtp, "DATA\r\n"); // Start pushing mail headers & email to the server from
the next line
fwrite($smtp, "From: \"My Name\" <my.email@job.com>>\r\n";
fwrite($smtp, "Reply-To: <my.email@job.com>\r\n";
fwrite($smtp, "To: to.whom@other.com\r\n";
fwrite($smtp, "Subject: My First Email\r\n";
fwrite($smtp, "Date: ".date("r")."\r\n";
fwrite($smtp, "MIME-Version: 1.0\r\n";
fwrite($smtp, "Content-type: text/plain;\r\n";
fwrite($smtp, "\r\n"; // Blank line before the body
fwrite($smtp, "Body of email\r\n";
fwrite($smtp, "\r\n";
fwrite($smtp, ".\r\n"); // Send a dot to tell the server you wanna stop pushing the
headers.
fwrite($smtp, "QUIT\r\n"); // Stop building up mail & send it
fclose($smtp); // Close connection.
Those might not be the best way but it sure works. I had some problems sending lots of headers
(multipart mail) using mail() / imap_mail(). Works great this way.