llau Posted October 28, 2008 Share Posted October 28, 2008 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 <[email protected]>"; // 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 https://forums.phpfreaks.com/topic/130439-sending-email-from-php-to-exchange-server-on-local-network/ Share on other sites More sharing options...
llau Posted October 29, 2008 Author Share Posted October 29, 2008 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 https://forums.phpfreaks.com/topic/130439-sending-email-from-php-to-exchange-server-on-local-network/#findComment-677418 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.