0

can i have this function send email through smtp?

    function send()
{
    if(mail($this->to, $this->subject, $this->body, $this->headers)) return         TRUE;
    else return FALSE;
}

this is part of following code:

    class sendMail
    {
    var $to;
    var $cc;
    var $bcc;
    var $subject;
    var $from;
    var $headers;
    var $html;

    function sendMail()
    {
        $this->to       = "test@mail.com";
    #$this->to       = "test@test.com";
        $this->cc       = NULL;
        $this->bcc      = NULL;
        $this->subject  = NULL;
        $this->from     = NULL;
        $this->headers  = NULL;
        $this->html     = FALSE;
    }

    function getParams($params)
    {
        $i = 0;
        foreach ($params as $key => $value) {
            switch($key) {
                case 'Submit':
                    NULL;
                break;
                default:
                        if ($key == 'email')
                        {
                        $this->from     = $value;
                        $this->subject  ="Contactgegevens from " . $value . " at www.webandeve.nl ";
                     }
                    $this->body[$i]["key"]     = str_replace("_", " ", ucWords(strToLower($key)));
                    $this->body[$i++]["value"] = $value;
            }
        }
    }

    function setHeaders()
    {
        $this->headers = "From: $this->from\r\n";
        if($this->html === TRUE) {
            $this->headers.= "MIME-Version: 1.0\r\n";
            $this->headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
        }
    }

    function parseBody()
    {
        $count = count($this->body);
        for($i = 0; $i < $count; $i++) {
            if($this->html) $content.= "<b>";
            $content .= $this->body[$i]["key"].': ';
            if($this->html) $content.= "</b>";
            if($this->html) $content .= nl2br($this->body[$i]["value"])."\n";
            else $content .= $this->body[$i]["value"];
            if($this->html) $content.= "<br>\n";
            else $content.= "\n".str_repeat("-", 80)."\n";
        }
        if($this->html) {
            $content = "
            <style>
                BODY {
                  font-family: verdana;
                  font-size: 10;
                }
            </style>
            ".$content;
        }
        $this->body = $content;
    }

    function send()
    {
        if(mail($this->to, $this->subject, $this->body, $this->headers)) return TRUE;
        else return FALSE;
    }

    function set($key, $value)
    {
        if($value) $this->$key = $value;
        else unset($this->$key);
    }

    function get_location()
    {
        return header('Location: thankyou.htm');break;
     }

}

I've been looking for a simple solution but cannot find any (for my knowledge of php) but Git and some full replacements of my script.

Chetan Ameta
  • 7,696
  • 3
  • 29
  • 44
  • So what is you exact problem? – Markus Feb 09 '16 at 08:22
  • Possible duplicate of [Send email using the GMail SMTP server from a PHP page](http://stackoverflow.com/questions/712392/send-email-using-the-gmail-smtp-server-from-a-php-page) – vard Feb 09 '16 at 08:28
  • i want the function so it does authenticate with a smpt server and send the email with smtp. –  Feb 09 '16 at 08:42
  • You can use this one: [PHPMailer](https://github.com/PHPMailer/PHPMailer), it is fairly easy to use. – Tom Feb 09 '16 at 08:51
  • i know i can use phpmailer, but i want to implement the smtp function in the above code. –  Feb 09 '16 at 08:53

1 Answers1

1

If you want to use your SMTP mail config with the mail() function you need to set the SMTP config in your php.ini.

See E-Mail configuration for details.

However I would recommend the use of a third party lib like PHPMailer