websoftexpert Posted June 15, 2012 Share Posted June 15, 2012 Hi I want to send HTML Email with SMTP Authentication but unable to that. I get a code in which I can send Plain Email with SMTP Authentication but not working with HTML Email Plz help Thanks a Quote Link to comment https://forums.phpfreaks.com/topic/264221-html-email-with-smtp-authentication/ Share on other sites More sharing options...
trq Posted June 15, 2012 Share Posted June 15, 2012 We can't help without seeing your code. Quote Link to comment https://forums.phpfreaks.com/topic/264221-html-email-with-smtp-authentication/#findComment-1354103 Share on other sites More sharing options...
websoftexpert Posted June 17, 2012 Author Share Posted June 17, 2012 Here is code SMTPClass.php 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; } } Index.php $SmtpServer="mail.domainnama.com"; $SmtpPort="25"; $SmtpUser="[email protected]"; $SmtpPass="password"; include('SMTPClass.php'); if($_SERVER["REQUEST_METHOD"] == "POST") { $to = [email protected]; $from = [email protected]; $subject = "Subject here"; $body = $_POST['message']; $body = 'Hello [email protected], <BR><BR> The password for your account at http://domainname.com/ has been reset. <BR><BR> Your Ligin Id is [email protected] and Password is xxxxxxxx . Please login and change your password immediately.<BR><BR> Please <a href="http://domainname.com/">click here</a> to Login. <BR><BR> Thanks & regards <BR><BR> Webmaster (domainname.com) <BR><BR>'; $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body); $SMTPChat = $SMTPMail->SendMail(); Important note : I have not written the above code but tested it. it works for plain email but not for html email. I also want send CC and BCC also. Any help will be appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/264221-html-email-with-smtp-authentication/#findComment-1354630 Share on other sites More sharing options...
boompa Posted June 17, 2012 Share Posted June 17, 2012 Save yourself the headache and use PHPmailer or SwiftMailer Quote Link to comment https://forums.phpfreaks.com/topic/264221-html-email-with-smtp-authentication/#findComment-1354636 Share on other sites More sharing options...
websoftexpert Posted June 18, 2012 Author Share Posted June 18, 2012 Thanks for information Save yourself the headache and use PHPmailer or SwiftMailer Quote Link to comment https://forums.phpfreaks.com/topic/264221-html-email-with-smtp-authentication/#findComment-1354821 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.