Mail sending through socket
Class MailCls {private $ mEmails; function setEmailInfo ($ emails) {if (is_array ($ emails )) {$ this-> mEmails ['email _ to'] = $ emails ['email _ to']; # process the Mail title if (isset ($ emails ['email _ subobject']) |! Empty ($ emails ['email _ subobject']) {eval ("$ email_subject = "". $ emails ['email _ subobject']. ""; "); $ email_subject = str_replace (" ",'', str_replace ("", '', $ emails ['email _ subobject']); $ this-> mEmails ['email _ subobject'] = $ emails ['email _ subobject'];} # process the email content if (isset ($ emails ['email _ message']) |! Empty ($ emails ['email _ message']) {eval ("$ email_message = "". $ emails ['email _ message']. ""; "); $ emails ['email _ message'] = str_replace (". ",".. ", str_replace ("","", $ emails ['email _ message']); $ this-> mEmails ['email _ message'] = $ emails ['email _ message'];} # process the Mail source if (isset ($ emails ['email _ from']) |! Empty ($ emails ['email _ from']) $ this-> mEmails ['email _ from'] = $ emails ['email _ from']; else $ this-> mEmails ['email _ from'] = '';} function getEmails ($ elements) {if (isset ($ elements) |! Empty ($ elements) return $ this-> mEmails [$ elements]; else return $ this-> mEmails;} function _ destruct () {unset ($ this) ;}} class sendMail extends MailCls {private $ mMailCfg; function _ construct ($ mailcfg) {if (is_array ($ mailcfg )) $ this-> mMailCfg = $ mailcfg;} # function of sending emails sendMails () {if (! $ Fp = fsockopen ($ this-> mMailCfg ['server'], $ this-> mMailCfg ['port'], $ errno, $ errstr, 30 )) {errorlog ('smtp ', "($ this-> mMailCfg [server]: $ this-> mMailCfg [port]) CONNECT-Unable to connect to the SMTP server, please check your "mail_config.php ". ", 0);} stream_set_blocking ($ fp, true); $ lastmessage = fgets ($ fp, 512); if (substr ($ lastmessage, 0, 3 )! = '000000') {errorlog ('smtp ', "$ this-> mMailCfg [server]: $ this-> mMailCfg [port] CONNECT-$ lastmessage", 0 );} fputs ($ fp, ($ this-> mMailCfg ['auth']? 'Ehlo': 'helo'). "hoodong"); $ lastmessage = fgets ($ fp, 512); if (substr ($ lastmessage, 0, 3 )! = 220 & substr ($ lastmessage, 0, 3 )! = 250) {errorlog ('smtp ', "($ this-> mMailCfg [server]: $ this-> mMailCfg [port]) HELO/EHLO-$ lastmessage ", 0);} while (1) {$ lastmessage = fgets ($ fp, 512); if (substr ($ lastmessage, 3, 1 )! = '-' | Empty ($ lastmessage) {break ;}} if ($ this-> mMailCfg ['auth ']) {fputs ($ fp, & quot; auth login & quot;); $ lastmessage = fgets ($ fp, 512); if (substr ($ lastmessage, 0, 3 )! = 334) {errorlog ('smtp ', "($ this-> mMailCfg [server]: $ this-> mMailCfg [port]) auth login-$ lastmessage ", 0);} fputs ($ fp, base64_encode ($ this-> mMailCfg ['auth _ username']). ""); $ lastmessage = fgets ($ fp, 512); if (substr ($ lastmessage, 0, 3 )! = 334) {errorlog ('smtp ', "($ this-> mMailCfg [server]: $ this-> mMailCfg [port]) USERNAME-$ lastmessage", 0 );} fputs ($ fp, base64_encode ($ this-> mMailCfg ['auth _ password']). ""); $ lastmessage = fgets ($ fp, 512); if (substr ($ lastmessage, 0, 3 )! = 235) {errorlog ('smtp ', "($ this-> mMailCfg [server]: $ this-> mMailCfg [port]) PASSWORD-$ lastmessage", 0 );} $ email_from = $ this-> mMailCfg ['from'];} fputs ($ fp, "MAIL from :". preg_replace ("/. *. */"," \ 1 ", $ this-> getEmails ('email _ from ')). ""); $ lastmessage = fgets ($ fp, 512); if (substr ($ lastmessage, 0, 3 )! = 250) {fputs ($ fp, "mail from: getEmails ('email _ from ')). ">"); $ lastmessage = fgets ($ fp, 512); if (substr ($ lastmessage, 0, 3 )! = 250) {errorlog ('smtp ', "($ this-> mMailCfg [server]: $ this-> mMailCfg [port]) mail from-$ lastmessage ", 0) ;}} foreach (explode (',', $ this-> getEmails ('email _ to') as $ to_user) {$ to_user = trim ($ to_user ); if ($ to_user) {fputs ($ fp, "rcpt to: $ to_user"); $ lastmessage = fgets ($ fp, 512); if (substr ($ lastmessage, 0, 3 )! = 250) {fputs ($ fp, "rcpt to:"); $ lastmessage = fgets ($ fp, 512); errorlog ('smtp ', "($ this-> mMailCfg [server]: $ this-> mMailCfg [port]) rcpt to-$ lastmessage", 0) ;}} fputs ($ fp, "DATA"); $ lastmessage = fgets ($ fp, 512); if (substr ($ lastmessage, 0, 3 )! = 354) {errorlog ('smtp ', "($ this-> mMailCfg [server]: $ this-> mMailCfg [port]) DATA-$ lastmessage", 0 );} fputs ($ fp, ":". $ this-> getEmails ('email _ '). "From :". $ this-> getEmails ('email _ from '). "Subject :". str_replace ("", '', $ this-> getEmails ('email _ subobject ')). "". $ this-> getEmails ('email _ message '). ". "); fputs ($ fp," QUIT ");} function getEmailCfg ($ elements) {if (isset ($ elements) |! Empty ($ elements) return $ this-> mMailCfg [$ elements]; else return $ this-> mMailCfg;} function _ destruct () {unset ($ fp ); unset ($ this) ;}}/* @ call demo. set the following information @*/################################# #######################################$ emails = array ('email _ to' => 'injection. mail@gmail.com ', # recipient address 'email _ subobject' => 'test', # email subject 'email _ message' => 'ksadasdasdsadasfafdasfdsaff ', # Mail body 'email _ from' => '', # Mail source ); ######################################## ################################### $ mailcfg ['server'] = 'smtp .gmail.com '; # smtp server address $ mailcfg ['port'] = '25'; # smtp port $ mailcfg ['auth'] = 1; # Show Author $ mailcfg ['from'] = 'Gmail '; # sender address $ mailcfg ['auth _ username'] = 'injection _ at@hotmail.com '; # sender's email address $ mailcfg ['auth _ password'] = '000000'; # sender's email password # Call: $ sm = new sendMail ($ mailcfg ); $ sm-> setEmailInfo ($ emails); $ sm-> sendMails ();