Acknowledged74 Posted August 20, 2014 Share Posted August 20, 2014 HiI have a simply working SMTP form, however I need this to send to a yahoo.com email address, what can I add to achieve this?SmtpConfig.php==============<?php//Server Address$SmtpServer="91.186.30.25";$SmtpPort="25"; //default$SmtpUser="things@wilsoncarandvanrental.co.uk";$SmtpPass="things123";?>SmtpClass.php=============<?phpclass SMTPClient{// A function for Setting up SMTPfunction 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;//Setting Default port Valueif ($SmtpPort == ""){$this->PortSMTP = 25;}else{$this->PortSMTP = $SmtpPort;}}//Sending the Mailfunction 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;}}?>mail.php========<?php//Include Class And Configinclude('SmtpConfig.php');include('SmtpClass.php');//Check the Request Methodif($_SERVER["REQUEST_METHOD"] == "POST"){$to = $_POST['to'];$from = $_POST['from'];$subject = $_POST['sub'];$body = $_POST['message'];// Send the mail Using the class$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);$SMTPChat = $SMTPMail->SendMail();}// After Exit, show the form?><form method="post" action="">To:<input type="text" name="to" />From :<input type='text' name="from" />Subject :<input type='text' name="sub" />Message :<textarea name="message"></textarea><input type="submit" value=" Send " /></form>Probably quite straight form, but of course I don#t know how :0)Much appreciated. Quote Link to comment Share on other sites More sharing options...
Acknowledged74 Posted August 20, 2014 Author Share Posted August 20, 2014 (edited) Actually first things first there are even error for the above which I've sourced from - http://www.9lessons.info/2009/10/send-mail-using-smtp-and-php.htmlMan I soooo hate SMTP, I've never got my hand around it, so annoying my hosting doesn't support Mail () Edited August 20, 2014 by Acknowledged74 Quote Link to comment Share on other sites More sharing options...
Acknowledged74 Posted August 21, 2014 Author Share Posted August 21, 2014 (edited) OK so it: $to = 'myaddress@yahoo.com'; There are no error ,but the email doesn't get throught to the yahoo account. Edited August 21, 2014 by Acknowledged74 Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 21, 2014 Share Posted August 21, 2014 (edited) I doubt the code you've posted to be working. There are too many occurrences could go wrong here. My advice to do this is using some php mail library, either swiftmailer or phpmailer. An example in swiftmailer using the yahoo mail server: <?php require_once $_SERVER['DOCUMENT_ROOT'] . '/swiftmailer-master/lib/swift_required.php'; date_default_timezone_set('America/Toronto'); // Create the Transport $transport = Swift_SmtpTransport::newInstance('smtp.mail.yahoo.com',465,'ssl') ->setUsername('your_account_name@yahoo.com') ->setPassword('password') ; // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); // Create a message $message = Swift_Message::newInstance('Some subject..') ->setFrom(array('your_account_name@yahoo.com' => 'Acknowledged74')) ->setTo(array('Acknowledged74@gmail.com' => 'Acknowledged74')) ->setBody('Body content ....') ; // Send the message $result = $mailer->send($message); A quick reference about it, click! Edited August 21, 2014 by jazzman1 Quote Link to comment 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.