Jump to content

PHP, Sending E-Mail, and Exchange Via SSL


criticman

Recommended Posts

I need to send e-mail from our website via our hosted Exchange server, which requires SSL connections (for Outlook 2007, it specifies to use TLS if that matters any)

 

I have the SMTP address for use with the Exchange server.  I can telnet to it on the SSL port (465) from our Linux server and it connects, responds validly as being our Exchange box.  It HAS to be over SSL.  I found an "SSL using PEAR:Mail" tutorial, tried the following:

<?php
// PHP Pear Mail Extension
require_once "Mail.php";

$from = "XYZ <[email protected]>";
$to = "XYZ <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "smtp.yz.net";
$port = "465";
$username = "[email protected]";
$password = "XyZxYz";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
	'port' => $port,
	'auth' => true,
	'username' => $username,
	'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?>

 

And I get the following error:

[pre]authentication failure [sMTP: Invalid response code received from server (code: 530, response: 5.7.0 Must issue a STARTTLS command first)][/pre]

 

Our Exchange provider could care less, as our Outlook and OWA, as well as ActiveSync e-mail is working just fine...

 

I am tired of routing my employer's web email through my personal company's web server (using standard SMTP auth on a Linux box) instead of using their server, especially since users will randomly end up missing a message depending on the receiving mail server and whether or not is says the sender is forged (showing company's email addresses, using my server instead).

Link to comment
https://forums.phpfreaks.com/topic/96036-php-sending-e-mail-and-exchange-via-ssl/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.