Configure mail server to work with PHP

后端 未结 3 614
轻奢々
轻奢々 2020-12-22 02:51

My current project is a form that receives input from a user. After I receive that data, I must send a warning/report to a few email addresses, including the user who insert

3条回答
  •  旧巷少年郎
    2020-12-22 02:53

    It's very likely you need authentication. This could be as simple as providing your username and password to the email account you want to send from.

    If that's the case, I'd suggest you use the PEAR Mail extension. There's a function called factory that allows you to do authentication with an smtp server. (Including SSL encryption, if you discover your server needs it)

    http://pear.php.net/manual/en/package.mail.mail.factory.php

    Your code would look a little like this:

    $smtp = Mail::factory('smtp',
      array ('host' => $host,
       'port' => $port,
       'auth' => true,
       'username' => $username,
       'password' => $password));
    
    $mail = $smtp->send($to, $headers, $body);
    

    Installing PEAR extensions on your server is not as hard as you might think.

提交回复
热议问题