• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1483
  • Last Modified:

Problems with sending mail from localhost

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
Rassac
Asked:
Rassac
  • 8
  • 4
  • 4
2 Solutions
 
dereshCommented:
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
 
RassacAuthor Commented:
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
 
Steve BinkCommented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
RassacAuthor Commented:
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
 
Steve BinkCommented:
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
 
RassacAuthor Commented:
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
 
Steve BinkCommented:
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
 
RassacAuthor Commented:
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
 
Steve BinkCommented:
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
 
RassacAuthor Commented:
No not really.... do you suggest anything else instead of SMTP server in IIS?
0
 
dereshCommented:
try changing line 5 to this:


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

Open in new window

0
 
RassacAuthor Commented:
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
 
RassacAuthor Commented:
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
 
dereshCommented:
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
 
RassacAuthor Commented:
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
 
dereshCommented:
i don't know because i dont know what is in test_mail.php?

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now