nightkarnation Posted July 12, 2012 Share Posted July 12, 2012 Hey Guys... I have the following easy and simple script to send valid SMTP emails from php, working perfectly: include('SMTPconfig.php'); include('SMTPclass.php'); $to = $_POST['to']; $from = $_POST['from']; $subject = $_POST['sub']; $body = $_POST['message']; $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body); $SMTPChat = $SMTPMail->SendMail(); } //but, below is the idea of what I need...to echo the result of the sent email...this is obviously not working, it says always success...how would I go to check this correctly?? if (SendMail) { echo "success"; } else { echo "error"; } Here's the SMTPclass.php for reference (if needed): class SMTPClient { function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body) { $this->SmtpServer = $SmtpServer; $this->SmtpUser = base64_encode ($SmtpUser); $this->SmtpPass = base64_encode ($SmtpPass); $this->from = $from; $this->to = $to; $this->subject = $subject; $this->body = $body; if ($SmtpPort == "") { $this->PortSMTP = 25; } else { $this->PortSMTP = $SmtpPort; } } function SendMail () { if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP)) { fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n"); $talk["hello"] = fgets ( $SMTPIN, 1024 ); fputs($SMTPIN, "auth login\r\n"); $talk["res"]=fgets($SMTPIN,1024); fputs($SMTPIN, $this->SmtpUser."\r\n"); $talk["user"]=fgets($SMTPIN,1024); fputs($SMTPIN, $this->SmtpPass."\r\n"); $talk["pass"]=fgets($SMTPIN,256); fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n"); $talk["From"] = fgets ( $SMTPIN, 1024 ); fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n"); $talk["To"] = fgets ($SMTPIN, 1024); fputs($SMTPIN, "DATA\r\n"); $talk["data"]=fgets( $SMTPIN,1024 ); fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n"); $talk["send"]=fgets($SMTPIN,256); //CLOSE CONNECTION AND EXIT ... fputs ($SMTPIN, "QUIT\r\n"); fclose($SMTPIN); // } return $talk; } } Thanks a lot in advance for the help! Cheers!! Quote Link to comment https://forums.phpfreaks.com/topic/265586-simple-and-working-smtp-emailerneed-to-echo-if-success-or-not-help/ Share on other sites More sharing options...
requinix Posted July 12, 2012 Share Posted July 12, 2012 $SMTPChat = $SMTPMail->SendMail(); Do whatever based on the value of $SMTPChat. Quote Link to comment https://forums.phpfreaks.com/topic/265586-simple-and-working-smtp-emailerneed-to-echo-if-success-or-not-help/#findComment-1361176 Share on other sites More sharing options...
nightkarnation Posted July 13, 2012 Author Share Posted July 13, 2012 Hello requinix, thanks for your reply! I tried with $SMTPChat and I get always the same value "Array" echo $SMTPChat; // = "Array" Any other suggestions? Thanks a lot!!! Quote Link to comment https://forums.phpfreaks.com/topic/265586-simple-and-working-smtp-emailerneed-to-echo-if-success-or-not-help/#findComment-1361178 Share on other sites More sharing options...
requinix Posted July 13, 2012 Share Posted July 13, 2012 The only mechanism available to you is whether $SMTPChat is an array (success) or null (failure), and all that indicates is whether the code could connect to the SMTP server. It has nothing which can tell you whether it actually sent the mail (mostly because the code doesn't even check that). Quote Link to comment https://forums.phpfreaks.com/topic/265586-simple-and-working-smtp-emailerneed-to-echo-if-success-or-not-help/#findComment-1361181 Share on other sites More sharing options...
nightkarnation Posted July 13, 2012 Author Share Posted July 13, 2012 Ok I understand, thanks a lot for your help! Do you think it would be difficult to add this kind of check? To be honest...I have no idea how to implement it. Quote Link to comment https://forums.phpfreaks.com/topic/265586-simple-and-working-smtp-emailerneed-to-echo-if-success-or-not-help/#findComment-1361183 Share on other sites More sharing options...
requinix Posted July 13, 2012 Share Posted July 13, 2012 I don't remember enough of SMTP but it would be somewhat easy. You can check the response from the server for each of the commands and look for specific good and specific bad messages. Quote Link to comment https://forums.phpfreaks.com/topic/265586-simple-and-working-smtp-emailerneed-to-echo-if-success-or-not-help/#findComment-1361188 Share on other sites More sharing options...
nightkarnation Posted July 13, 2012 Author Share Posted July 13, 2012 How would I do that? :-\ Thanks again!! Quote Link to comment https://forums.phpfreaks.com/topic/265586-simple-and-working-smtp-emailerneed-to-echo-if-success-or-not-help/#findComment-1361197 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.