Link to home
Start Free TrialLog in
Avatar of Rassac
RassacFlag for Malta

asked on

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

Avatar of deresh
deresh

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.

Avatar of Rassac

ASKER

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

Avatar of Steve Bink
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?
Avatar of Rassac

ASKER

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

Avatar of Rassac

ASKER

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.
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?
Avatar of Rassac

ASKER

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?
SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rassac

ASKER

No not really.... do you suggest anything else instead of SMTP server in IIS?
try changing line 5 to this:


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

Open in new window

Avatar of Rassac

ASKER

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.


Avatar of Rassac

ASKER

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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rassac

ASKER

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