Solved

Problems with sending mail from localhost

Posted on 2008-10-06
16
1,414 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 50

Assisted Solution

by:Steve Bink
Steve Bink earned 200 total points
Comment Utility
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
Comment Utility
No not really.... do you suggest anything else instead of SMTP server in IIS?
0
 
LVL 6

Expert Comment

by:deresh
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
i don't know because i dont know what is in test_mail.php?

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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

10 Experts available now in Live!

Get 1:1 Help Now