Jump to content

Sending email from PHP to Exchange Server on local Network


llau

Recommended Posts

I have been trying to send email from PHP scripts on a linux (centos/php5) to the local exchange 07 server. I added an alternate SMTP connector with a seperate IP address on the Exchange side, so that should not be the issue. I can telnet into the Exchange server on port 25 from teh linux box and manually send mail with no password, which porves that the alt SMTP connector is working. When I try to send mail via PHP script, I can not get the message through. I have tried standard PHP Mail as well as PEAR (smtp).

 

I feel I am overlooking something simple - Here is the error I get with the code (pasted below) (I changed the to/from addresses to something generic for this posting.)

 

Thanks in advance for any help...

 

 

Failed to connect to 192.168.100.98:25 [sMTP: Failed to connect socket: Permission denied (code: -1, response: )]Your message was not sent: Object id #5

 

CODE:

 

 

// Append a new include path to the existing path

ini_set("include_path", "$current_path:/var/www/html/pear/PEAR");

 

    include('Mail.php');

        include('Mail/mime.php');

 

        // Constructing the email

        $sender = "Leigh <leigh@no_spam.net>";                                  // Your name and email address

        $recipient = "Lou <llau@xxxxxx.com>";                              // The Recipients name and email address

        $subject = "Test Email";                                                // Subject for the email

        $text = 'This is a text message.';                                      // Text version of the email

        $html = '<html><body><p>This is a html message</p></body></html>';      // HTML version of the email

        $crlf = "\n";

        $headers = array(

                        'From'          => $sender,

                        'Return-Path'  => $sender,

                        'Subject'      => $subject

                        );

 

        // Creating the Mime message

        $mime = new Mail_mime($crlf);

 

        // Setting the body of the email

        $mime->setTXTBody($text);

        $mime->setHTMLBody($html);

 

        // Add an attachment

        $file = "Hello World!";

        $file_name = "Hello text.txt";

        $content_type = "text/plain";

#        $mime->addAttachment ($file, $content_type, $file_name, 0);

 

        // Set body and headers ready for base mail class

        $body = $mime->get();

        $headers = $mime->headers($headers);

 

        // SMTP params

        $smtp_params["host"] = "192.168.100.98"; // SMTP host

        $smtp_params["port"] = "25";              // SMTP Port (usually 25)

   

 

        // Sending the email using smtp

        $mail =& Mail::factory("smtp", $smtp_params);

        $result = $mail->send($recipient, $headers, $body);

        echo $result;

        if($result === 1)

        {

          echo("Your message has been sent!");

        }

        else

{

          echo("Your message was not sent: " . $result);

        }

 

 

 

Link to comment
Share on other sites

I have figured out a workaround. I am still not sure why the SMTP/Pear code did not work, however, I was able to get messages through using sendmail after I configured /etc/postfix/main.c on the linux box (Set    relayhost =[ip of exchange server] ). Not quite the answer I was looking for, but it does work.

 

 

         

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.