Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    408
    Thanks
    17
    Thanked 2 Times in 2 Posts

    php mail script smtp

    I'm not experienced with mail scripts. But I'm trying one out to get started. I'm not having much luck. The port is set to 995, which is correct. I tried 25 as well, but it still sent nothing. I have the security for the receiving email set to TLS. I don't know if that makes a difference. The script seems to run fine, but nothing's received. Any suggestions are welcome. Thanks! (EDIT: I just noticed, it looks like this server requires SSL. A whole other thing that Isn't in this, is it? How would I include that?)

    Right now I have the following 3 files.:

    The included files:
    Code:
    <?php
    //Server Address
    $SmtpServer="smtp.website.com";
    $SmtpPort="995"; //default
    $SmtpUser="username";
    $SmtpPass="password";
    ?>
    and ....

    Code:
    <?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 = 995;
    }
    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;
    }
    }
    ?>
    And for the the form page:
    Code:
    <?php
    include('SMTPconfig.php');
    include('SMTPClass.php');
    if($_SERVER["REQUEST_METHOD"] == "POST")
    {
    $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();
    
    print_r($_POST);
    
    }
    ?>
    <form method="post" action="">
    To:<input type="text" name="to" /><br/>
    From :<input type='text' name="from" /><br/>
    Subject :<input type='text' name="sub" /><br/>
    Message :<textarea name="message"></textarea><br/><br/>
    <input type="submit" value=" Send " />
    </form>
    Last edited by turpentyne; 11-08-2013 at 07:48 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •