How to send mail using PHP?

前端 未结 7 1527
谎友^
谎友^ 2020-11-30 15:00

I\'m using Windows Vista OS. PHP, MySQL as the database and Apache web server.

I want to send notification to those who want to join in my site. But the problem is w

7条回答
  •  -上瘾入骨i
    2020-11-30 15:23

    Use the Pear "Mail" class, which requires access to a separate SMTP server listening on port 25.

    Sample code follows:

    function sendmail($from, $to, $subject, $message, $headers)
    {
        if (is_array($to)) {
                $recipients = implode(', ', $to);
        } else {
            $recipients = $to;
        }
    
        $errorlevel = error_reporting();
        $headers["From"] = $from;
        $headers["To"] = $to;
        $headers["Subject"] = $subject;
    
        $params = array();
        $params["host"] = "localhost";
        $params["port"] = "25";
        $params["auth"] = false;
    
        error_reporting($errorlevel & ~E_WARNING);
    
        $mail_object =& Mail::factory("smtp", $params);
        $res = $mail_object->send($recipients, $headers, $message);
    
        error_reporting($errorlevel);
    
        return $res;
    }
    

    nb: this is old code - I don't recall now why I had to mask out E_WARNING

提交回复
热议问题