Solved

Send Email using Exchange Server

Posted on 2006-10-26
12
692 Views
Last Modified: 2010-05-18
at work we have a mail server, windows 2000 exchange Server to be specific.  We have PHP 5.1.4 installed and running on IIS.

im wanting to send emails using mail server, but the code ive put together dont seem to work.  when i run my script, i get no errors, but no emails come through to my mailbox either...

mailserver  IP is 192.168.0.2

<?php
require('classes/class.phpmailer.php');

$mail->Sender = 'administrator@companyname.com';

ini_set('sendmail_from',$mail->Sender);

$mail = new PHPMailer();
$mail->AddAddress('sdelaney@companyname.com','mlennon@companyname.com');
$mail->From = 'administrator@companyname.com';
$mail->FromName = 'Pegasus Intranet Gate Keeper';
$mail->Subject = 'Just Testing the SMPT Settings for the Intranet';
$mail->ContentType = 'text/html';
$mail->CharSet = 'iso-8859-1';
$mail->Priority = 1;
$mail->Body = '<p>Hello, This email has been send using the Pegasus Exchange Server (192.168.0.2)</p>';
$mail->Send();
$mail->ClearAddresses();
$mail->SmtpClose();
?>
0
Comment
Question by:ellandrd
  • 7
  • 3
  • 2
12 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 250 total points
ID: 17811167
The usage of addAddress is not 100% correct. It looks like you wnat to send the mails to two recipients with
$mail->AddAddress('sdelaney@companyname.com','mlennon@companyname.com');
it should be
$mail->AddAddress('sdelaney@companyname.com');
$mail->AddAddress('mlennon@companyname.com');

But the mails should have come to the first email-adress

also put an
echo $mail->ErrorInfo
to see ih phpmailer has encountred an error
0
 
LVL 18

Assisted Solution

by:ingwa
ingwa earned 250 total points
ID: 17811175
As you are using the PHPMailer classes (http://phpmailer.sourceforge.net/), I would recommend that in the class files, look for the authentication section.  I believe it should be contained in the file class.phpmailer.php.  Do a search for var $Host and you should find all the settings that need changed.  For example, point $Host to your exchange server, and put in the username and password necessary to connect to the server.  You may have to setup an account on the exchange server for the purposes of php authentication.

Hope this helps.
0
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 250 total points
ID: 17811176
ups forgot to add that you need

$mail->Host = '192.168.0.2';

to delive the mail via that smtp-server
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17811279
>>it should be
>>$mail->AddAddress('sdelaney@companyname.com');
>>$mail->AddAddress('mlennon@companyname.com');

Oh! OK, i was shown this way by another expert in the PHP TA...  they where obviously wrong them... damn and ive been shown other people this all along!

OK i'll fix this.

>>also put an
>>echo $mail->ErrorInfo
>>to see ih phpmailer has encountred an error

Ya sorry, ive added these since:

if($mail->Send())
      echo 'Message send!';
else
      echo 'Message not send!';

and all i get is: Message not send! so i'll add what you suggest again...

>>$mail->Host = '192.168.0.2';
>>to delive the mail via that smtp-server

ah - this would be good to have... if i want to send an email... ;-)

>>ingwa

Thank you for that advise - i wasnt sure if to go searching for options in that class file as i didnt want to muck the class up by editing it...but i'll take a look now

ive also checked my PHP.INI file on the exchange server and the setting are correct in terms of SMTP server address and port...

thanks guys, i'll reply in a few mins

Ellandrd
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17811288
Im not getting:

Language string failed to load: instantiate
Message not send!
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17811314
ingwa

Ive went into that class and set the username/password of the admin account and set host to 192.168.0.2 and set the from address to administrator@companyname.com...

still no difference...

ellandrd
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 18

Assisted Solution

by:ingwa
ingwa earned 250 total points
ID: 17811315
Hmm, you might find this page useful with the above error:

http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_21451918.html

Additionally, here's another link to check:

http://sourceforge.net/mailarchive/message.php?msg_id=6378870
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17811381
none of these seem to fix my issue.
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17811389
Ive changed my username to my account login username and now i get this:

Warning: fsockopen() [function.fsockopen]: unable to connect to 192.168.0.2:25 (An established connection was aborted by the software in your host machine. ) in c:\Inetpub\wwwroot\prelease\classes\class.smtp.php on line 105
Language string failed to load: connect_host
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17811499
ive already looked in the class.smtp.php and i cant make heads or tails of that code or where it might be going wrong..

any other options??
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17811961
cheers guys i got it working another way by using a remote SMTP server.

thanks for helping!

ellandrd
0
 
LVL 18

Expert Comment

by:ingwa
ID: 17811979
Hi Ellandrd, glad to hear you have the problem resolved.  Thanks for the points and the grade and have a great day.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now