I know of the mail() function but what I want to do is connect to a SMTP server (using sockets), send the needed commands and then close the socket. Can anyone show me how to do this or maybe give me a link to a site/tutorial that does this?
I also have another question regarding this issue; is it possible to check if an email is valid using sockets? Not just validate the pattern but validate the email itself…
Thanks, I’m gonna download that and take a look at it. The reason to why I started this thread was because I want to get the basics of how to communicate with a SMTP server using PHP and sockets. But thanks anyway!
I didn’t find anything that was of interest to me. I’ve tried to use fsockopen() to open a socket to the SMTP server but I just can’t make it work. This is what I’ve tried:
I got a reply on a swedish forum where a member pointed out to me that I haven’t logged in into the server. I’ve also read that the first command that you should send is the “HELO” command. Therefor, I tried this code but instead of getting a “250 OK” reply on the HELO command, I get a “220 smtp2-1-sn4.m-sp.skanova.net ESMTP Postfix”. What should I do next?
i’d suggest reading up on the RFC, the basics of mail are as follows though (summarizing what everyone else has stated already):
first, send HELO / EHLO to identify yourself (the latter if you’re using ESMTP). then, send the MAIL FROM, then RCPT TO, assuming you’re still good, then you can send DATA (which is the full email including headers).
a space after the headers determines the body of the message. finally, a “.” on a line by itself signifies the end of the email.
so is it working from your script to?
you need to read the response from the server, and then send your command. look at the get_lines function in that phpmailer class.smtp.php file. as pseudo-code:
You may want to try this class for composing and sending messages that comes with a wrapper function named smtp_mail() . It emulates the mail() function but it always send messages via SMTP regardless of your platform and even provides additional features like SMTP authetication that you may need.