Configure mail server to work with PHP

后端 未结 3 543
轻奢々
轻奢々 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:52

    Exchange supports regular SMTP mail delivery (it has to, otherwise it couldn't talk to the rest of the email world), so just point your PHP's configuration at the Exchange server as if it was a regular mail server.

    There's some .ini settings for mail, documented here: http://php.net/manual/en/mail.configuration.php#ini.smtp

    Assuming the exchange server doesn't require authentication and will accept mail from your server, that's all that should be required.

    followup:

    did you read the docs on the Mail package? the send() method returns TRUE on success, or a PEAR_Error object on failure. It will contain any details about the send attempt's failure, most likely you'd want $PEAR_Error:message. Full details here: http://pear.php.net/package/PEAR/docs/1.9.1/PEAR/PEAR_Error.html. Change your code from

    $mail_object->send($recipients, $headers, $mailmsg);
    

    to

    $status = $mail_object->send($recipients, $headers, $mailmsg);
    if ($status !== TRUE) {
        die("Error sending mail: " . $status::message);
    }
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-22 03:12

    Ok. Got it to work. Phew.

    I found out the reason, after reading alot. It was regarding a relay problem with the smtp exchange server.

    But I would have never got there if it wasn't for you people. xD

    Thank you all. =)

    0 讨论(0)
提交回复
热议问题