Solved

Problems with sending mail from localhost

Posted on 2008-10-06
16
1,416 Views
Last Modified: 2013-11-30
Hi,

I am getting an error while trying to send an automatic email notification through my IIS.

PHP.ini is set to: -
SMTP =localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

See code snippet below:
$our_email = xyz@gmail.com

$emailfrom  = $arVals['email'];

$our_subject = 'Email Notification - Thankyou for your interest!';

$from_us = 'Me';
 

$headers2 = 

   'From:' . $from_us . '<' . $our_email . '>' . "\r\n" .

   'Reply-To:' . $our_email . "\r\n" .

   'X-Mailer: PHP/' . phpversion();

$notification = 'hello';
 

mail($emailfrom, $our_subject, $notification, $headers2);

Open in new window

0
Comment
Question by:Rassac
  • 8
  • 4
  • 4
16 Comments
 
LVL 6

Expert Comment

by:deresh
ID: 22653567
dou you have localy (on server with iis) installed smtp/mail server. you need one if you intend to send mails through it ;)
for windows you have many free smtp servers which you could use.

0
 

Author Comment

by:Rassac
ID: 22653650
I guess I'm using the windows one from
control panel > Administrative Tools > Internet Information Services.

In fact the code in the snippet works perfectly fine for me.

Am I missing something?

<?

$to = "youremailaddress@domian.com";

$subject = "test from localhost";

$msg = "I completely understand SMTP servers now!";

$headers = "From: localhost@localhost.com\nReply-To: localhost@localhost.com";

$config = "-stfu@noob.com";

mail("$to", "$subject", "$msg", "$headers", "$config");

echo "finished!";

?>

Open in new window

0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 22687262
First, check the differences between line 7 of your working code snippet, and line 12 of your original code.  To help, here's the function header for mail():

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

Also, line 1 of your original code does not include quotes around the string.  Perhaps that is just a typo in the post, though...?

Otherwise, what is the exact error you are receiving?
0
 

Author Comment

by:Rassac
ID: 22687338
Hi routinet,


Yes line 1 double quotes is a mistake in the post. The error is:
SMTP server response: 501 5.5.4 Invalid Address in c:\Inetpub\wwwroot\hunggar\sql\process_form.php on line 72

Didn't quite understand why / what differences I have to check. Can you re-explain pls?

thanks.
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 22687437
Never mind...your headers are in the correct order.

The error you are receiving implies that the mail server either a) cannot deliver to the requested address or b) you are attempting to send from an unauthorized address.  I'm looking at (b) because of the ini snippet you posted originally:

>>> ; For Win32 only.
>>> ;sendmail_from = me@example.com

That sendmail_from should be set for Windows servers, or set in the "From" headers of the mail() call.  Your header, as built in the code, will look like this:

"Me<xyz@gmail.com>"

At the very least, you need a space between them.  

"Me <xyz@gmail.com>"

That assumes your mail server will recognize that format.  I would recommend setting the ini value to "xyz@gmail.com", and testing that first.  

0
 

Author Comment

by:Rassac
ID: 22692883
Hi Routinet,
I did the change in the php.ini file but I had no positive results. I used my yahoo email account. Could that be a problem?

Thanks.
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 22694035
It could be.  If the server is set up *properly*, you are not an open relay, and the only accounts that can send mail from it are in the domain managed by the server.  Have you set that server to require authentication for sending?
0
 

Author Comment

by:Rassac
ID: 22694048
I have Authentication as anonymous and Relay as "All except the list below" -  there nothing in the list. The "Allow all computers checkbox...." is ticked.

Does the above inspire something?
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 50

Assisted Solution

by:Steve Bink
Steve Bink earned 200 total points
ID: 22694073
I've never used the SMTP server in IIS, so I can't be of help there.  The error you are receiving is definitely from the server, and is probably due to the account not being authorized.  Do you have a domain set up for email?  Have you tried an email account managed by this server?
0
 

Author Comment

by:Rassac
ID: 22694081
No not really.... do you suggest anything else instead of SMTP server in IIS?
0
 
LVL 6

Expert Comment

by:deresh
ID: 22696735
try changing line 5 to this:


$headers = "From: localhost@localhost.com\r\nReply-To: localhost@localhost.com\r\n";

Open in new window

0
 

Author Comment

by:Rassac
ID: 22696763
OK I found one problem.... The script in the package downloaded had a small bug. The path to the included  files was incorrect. Now I fixed that and got this error message:


Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in c:\Inetpub\wwwroot\phpMailer_v2.2.1\examples\class.smtp.php on line 122

SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (40) Mailer Error: SMTP Error: Could not connect to SMTP host.


0
 

Author Comment

by:Rassac
ID: 22696767
The error above came from using the test_gmail.php file ...
Using test_sendmail.php on my localhost I got the error "Mailer Error: Could not execute: /usr/sbin/sendmail"

However I managed to use the sendmail from my hosting account but not the test_gmail one.
0
 
LVL 6

Accepted Solution

by:
deresh earned 300 total points
ID: 22696788
gmail uses ssl on smtp su you need ssl support in php:
enable openssl.dll in php.ini and copy required dll in %SYSTEMROOT%\system32\ folder

and windows doesn't have sendmail. this is the reason you MUST use smtp to send mail on windows.

for other free smtp servers for windows you could try:
http://www.softstack.com/freesmtp.html

i haven't used php ond windows for quite some time, but this above should work as expected ( remember to turn off IIS SMTP off before installing other one)


0
 

Author Comment

by:Rassac
ID: 22696837
Thanks,

That's great! I managed to use all scripts - only one I didn't manage to use from my localhost;  the test_mail.php. Seems I got some problems with the IIS SMTP server. Still strange though, because the test_smtp.php worked from my localhost.

However I think I read somewhere that the test_mail.php is slower than the others. Am I correct?
0
 
LVL 6

Expert Comment

by:deresh
ID: 22698153
i don't know because i dont know what is in test_mail.php?

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

948 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

22 Experts available now in Live!

Get 1:1 Help Now