Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

IIS Hosted webpage sending email to Exchange 5.5/2000 server via SMTP

Posted on 2003-03-13
6
Medium Priority
?
248 Views
Last Modified: 2010-04-06
Hi,

My resident programmer is having problems writing a webpage in PHP that submits an email containing web page information to email account on the companies Exchange Server via SMTP.  
The code he wrote works fine when using a (non production) Linux server that is running send mail, however the projects call for using the Live (production) Exchange Server.  

There is a firewall between the 2 servers, but is open for port 25.

The programmer says the code is correct, however he is only change the SMTP server variable.

Here is a copy of the code that is currently work with a Linux box

Can anyone help ?

cheers
Mark

<?php

    function read_response($socket) {
        // This will contain the last status message from the SMTP server
        $response    = fgets($socket, 1024);
        $status     = substr($response, 0, 1); // Grab the first number of the status msg
        $message     = substr($response, 0, strlen(trim($response)));
        $resp_msg    = $message . "<br>";
        return array($status=>$resp_msg);
    }

    function send_email($settings, $return_errors = true) {
        // Set some constants
        $STATUS_OK             = "2";
        $STATUS_DATA_OK     = "3";
        $CRLF                 = "\n";

        // Pull in any globals
        global $error, $HTTP_HOST;

        // Set the success or fail flag to fail
        $send_success = false;
        unset($error);

        // Set some defaults
        if (empty($settings[crlf]))     $settings[crlf]     = "<br>";
        if (empty($settings[host]))     $settings[host]     = "smtp.mydomain.com";      
        if (empty($settings[port]))     $settings[port]     = "25";
        if (empty($settings[domain]))     $settings[domain]     = $_SERVER["HTTP_HOST"];
        if (empty($settings[prior]))     $settings[prior]     = 3; // Normal Priority

        // Let's do some error checking
        if (empty($settings[to]))         $error .= "TO address not specified" . $settings[crlf];
        if (empty($settings[from]))     $error .= "FROM address not specified" . $settings[crlf];
        if (empty($settings[msg]))         $error .= "MSG not speficied" . $settings[crlf];
        if (empty($settings[domain]))     $error .= "DOMAIN not specified" . $settings[crlf];

        if (empty($settings[reply]))    $settings[reply] = $settings[from];
        if (empty($settings[errors]))    $settings[errors] = $settings[reply];

        // Pull out the simple email if they are putting in 'name <email@domain.com>'
        if (ereg("(([[:alnum:]]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", $settings[to], $reg_array)) {
            $simple_to = $reg_array[0];
        } else {
            $simple_to = $settings[to];
        }
        if (ereg("(([[:alnum:]]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", $settings[from], $reg_array)) {
            $simple_from = $reg_array[0];
        } else {
            $simple_from = $settings[from];
        }

        // If we already have errors, don't even attempt to open the socket
        if (!empty($error)) {
            if ($return_errors) {
                return $error;
            } else {
                return false;
            }
        }

        if ($socket = fsockopen($settings[host], $settings[port])) {
            list($status, $resp_msg) = each(read_response($socket));
            if ($status == $STATUS_OK) {
                fputs($socket, "HELO " . $settings[domain] . $CRLF);
                list($status, $resp_msg) = each(read_response($socket));
                if ($status == $STATUS_OK) {
                    fputs($socket, "MAIL FROM:" . $simple_from . $CRLF);
                    list($status, $resp_msg) = each(read_response($socket));
                    if ($status == $STATUS_OK) {
                        fputs($socket, "RCPT TO: " . $simple_to . $CRLF);
                        list($status, $resp_msg) = each(read_response($socket));
                        if ($status == $STATUS_OK) {
                            fputs($socket, "DATA" . $CRLF);
                            list($status, $resp_msg) = each(read_response($socket));
                            if ($status == $STATUS_DATA_OK) {
                                $buffer = "From: " . $settings[from] . $CRLF;
                                $buffer .= "To: " . $settings[to] . $CRLF;
                                if (!empty($settings[cc])) {
                                    $buffer .= "CC: " . $settings[cc] . $CRLF;
                                }
                                if (!empty($settings[bcc])) {
                                    $buffer .= "BCC: " . $settings[bcc] . $CRLF;
                                }
                                $buffer .= "Reply-To: " . $settings[reply] . $CRLF;
                                $buffer .= "Errors-To: " . $settings[errors] . $CRLF;
                                $buffer .= "Bounce-To: " . $settings[errors] . $CRLF;
                                $buffer .= "X-Priority: " . $settings[prior] . $CRLF;
                                $buffer .= "X-Mailer: QUICK-N-DIRTY Mailer w/PHP " . phpversion() . $CRLF;
                                $buffer .= "Subject: " . $settings[subject] . $CRLF;
                                $buffer .= $CRLF;
                                $buffer .= $settings[msg];

                                // echo nl2br($buffer);
                                if (fputs($socket, $buffer . "$CRLF.$CRLF")) {
                                    list($status, $resp_msg) = each(read_response($socket));
                                    if ($status == $STATUS_OK) {
                                        $send_success = true;
                                        fputs($socket, "QUIT" . $CRLF);
                                    }
                                } // Close fputs of buffer
                            } // Close status of DATA command
                        } // Close status of RCPT TO command
                    } // Close status of MAIL FROM command
                } // Close status of HELO command
            } // Close status of SMPT welcome
            fclose($socket);
        } else {
            $error .= "Unable to establish initial connection with " . $settings[host] . ":" . $settings[port] . $settings[crlf];
        }

        if (!empty($resp_msg)) {
            $error .= $resp_msg . $settings[crlf];
        }

        if ($send_success) {
            return true;
        } else {
            if ($return_errors && isset($error)) {
                return $error;
            } else {
                return false;
            }
        }
    }

?>
0
Comment
Question by:markcrees
6 Comments
 
LVL 4

Accepted Solution

by:
iozturk earned 672 total points
ID: 8134696
Activate your SMTP service and in internet Information Services aplet, right click SMTP ->properties->delivery->advanced delivery write smart host as [100.100.100.100]
and change change smtp server variable to your server.
0
 
LVL 4

Assisted Solution

by:arthuryeung
arthuryeung earned 664 total points
ID: 8135106
You probably have not enable relay mail in your SMTP server.

You can go to the SMTP Server, in your IIS Management Console and right click on your SMTP Server -> Properties -> Access -> Relay -> Add

Try to add the ip of the Web Server to the granted list.

hope this can help
0
 
LVL 4

Expert Comment

by:arthuryeung
ID: 8135155
You probably have not enable relay mail in your SMTP server.

You can go to the SMTP Server, in your IIS Management Console and right click on your SMTP Server -> Properties -> Access -> Relay -> Add

Try to add the ip of the Web Server to the granted list.

hope this can help
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Assisted Solution

by:bolesj
bolesj earned 664 total points
ID: 8137699


Have you tried using the builtin php Mail() command to test?

http://www.php.net/manual/en/ref.mail.php

[just a thought]
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 9115241
This question has been classified abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.

<note>
Unless it is clear to me that the question has been answered I will recommend delete.  It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
</note>

If the user does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp


Cd&

0
 
LVL 6

Expert Comment

by:Programming_Gal
ID: 9648722
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split between iozturk, arthuryeung, bolesj

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Programming_Gal
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question