Forum Moderators: coopster

Message Too Old, No Replies

Mail ()

Problems with Mail function

         

IHaveToUseWindows

4:29 pm on Nov 14, 2005 (gmt 0)

10+ Year Member



Hi. I am using (uggh) Windows to host a website, with Apache, PHP5, MySQL 4, and Perl 5.8. However, when I try and use the php mail () function, it doesn't work. At first I thought it could be a firewall problem, but turning my firewall off didn't help.

Are there any known problems with the mail () function? I not, could someone please give me some advice as to what could be wrong

Thanks

Anyango

5:39 pm on Nov 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi There!

Welcome to Webmasterworld.

mail() function needs to have an smtp server running and configured to be able to send out emails. does your system have smtp server running and its settings are configured in php.ini?

Regards,
Kami

IHaveToUseWindows

4:45 am on Nov 15, 2005 (gmt 0)

10+ Year Member



This is all ic ould find about mail in php.ini

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

Anyango

5:53 am on Nov 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes settings are ok for local computer but definitely you need to have an smtp server running on your machine. you could search in any famous search engine for "free smtp server" , download,install,run and then call your mail() function and it will be ok.

Regards
Kami

Anyango

8:13 am on Nov 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



or alternatively if you have access to another smptp server elsewhere, you can enter its details in your php.ini

IHaveToUseWindows

11:09 am on Nov 15, 2005 (gmt 0)

10+ Year Member



My Google search for 'free smtp server' brought up a lot of results and I was hoping someone would be able to advise me as to which one I could use. I am specifically looking for one that is easy to install, configure and that's hassle free.

Thanks

chrisjoha

12:22 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



I used Xmail on windows. That was relatively pain free.

doodlebee

12:37 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



I know exactly how you feel. I just had a client who - after the initial design was completed and all tests for functionality worked fine on my test Unix server - told me that they were running their site on a Windows IIS system. ("Was that important to know?" they asked. Aaaagggh!)

Anyway, I ran in to this *exact* issue, and I found a little program called PHPMailer. It's awesome. There *is* an SMTP server on the client's server, but the tech guys refused to change the settings to allow relayed messages (most likely, they just didn't know *how* to do it - they had a funny way of disappearing when I had tech questions!) - PHPMailer allows you to set the username and password from the SMTP server in a separate file that gets called in by your current PHP Mail() form. So it authenticates all emails coming into the server - and it doesn't rewuire you to change any settings. It was really easy to use.

I used the program (you can get it for free at SourceForge) and I beefed it up a bit (which made things a *lot* easier) with a tutorial from PHPFreaks.com

Hope that helps ya!

coopster

2:23 pm on Nov 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You might also be able to use your local ISP's mail server. There is a thread in the PHP Forum Library describing Installing PHP5 Under Windows XP and Apache [webmasterworld.com] that shows some of the configuration settings necessary to get mail() working.

IHaveToUseWindows

7:33 pm on Nov 17, 2005 (gmt 0)

10+ Year Member



Sorry, but I am still having problems sending mail. My php.ini [Mail Function] is as follows:

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

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

The php script I have tried running is:

<?php
$to = "email@example.com";
$subject = "Test PHP email";
$body = "Message text here";
$headers = "From: email@example.com\n";

if(mail("$to,$subject,$body,$headers\n"))
{
echo "An e-mail was sent to $to with the subject: $subject";
}
else
{
echo "There was a problem sending the mail. Check your code and make sure that the e-mail address $to is valid";
}
?>

But, I always get the "There was a problem..." message.

Does it watter what email address i specify in sendmail_from? That is my email address? I want to use something like server@example.com but it doesn't exist so I thought it might not work.

I have QK SMTP Server 3, listening on port 25.
I have also tried disabling my firewall... But nothing seems to work

Does anyone have any suggestions as to why this won't work?

[edited by: eelixduppy at 5:23 am (utc) on Sep. 14, 2007]

Anyango

7:42 pm on Nov 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What are those double quotes doing here?


if(mail("$to,$subject,$body,$headers\n"))

it should be


if(mail($to,$subject,$body,"$headers\n"))

that's the problem.
;)

IHaveToUseWindows

10:05 am on Nov 18, 2005 (gmt 0)

10+ Year Member



Ah, right

The only problem is that it tells me it was sent, my smtp server receives the request, but the smtp server crashes on this error:


Message FROM: <email@example.com> TO: <email@example.com> directly fail! Connect fail: Socket Error # 10060 Connection timed out. Wait for retry...

The email address email@example.com is specified in my php.ini [mail function] - send_from

Does the address specified in php.ini have to, in some way, be associated with my smtp server?

Can i change it to a non-existant one, such as server@isp.co.za or something to that effect?

I am still trying to run the script:


<?php

$to = "email@example.com";
$subject = "Test PHP email";
$body = "PHP is one of the best scripting languages around";
$headers = "From: email@example.com\n";

if(mail($to,$subject,$body,"$headers\n"))
{
echo "An e-mail was sent to $to with the subject: $subject";
}
else
{
echo "There was a problem sending the mail. Check your code and make sure that the e-mail address $to is valid";
}

?>

[edited by: eelixduppy at 5:24 am (utc) on Sep. 14, 2007]

Anyango

1:28 pm on Nov 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try removing "From:" temporarily from your headers and then check what does it say.

IHaveToUseWindows

7:02 am on Nov 19, 2005 (gmt 0)

10+ Year Member



Nope, it still crashes...

doodlebee

1:34 pm on Nov 19, 2005 (gmt 0)

10+ Year Member



Just curious -

did you try the PHPMailer thing I suggested?

IHaveToUseWindows

3:19 pm on Nov 19, 2005 (gmt 0)

10+ Year Member



Yes, i did... But my smtp server still crashes on the same error...

Is there any way to implement some other way of sending - not via the localhost... There isn't a dedicated smtp server either. Is there perhaps a smtp server that anyone can route their email through? (eg maybe route the email through gmail using my credentials... or something to that effect)

Thanks

doodlebee

4:08 pm on Nov 19, 2005 (gmt 0)

10+ Year Member



Okay - I see you're trying to route mail through your gmail account (that's correct, right?)

I've heard of people having issues with this before...but wouldn't you know it, I can't find any of my old links now. However, I did find this (I won't link it, I'll just copy what they said):

"Basic Procedure

Gmail allows you to forward incoming messages to any other e-mail address. Go to the Settings page and then to the Forwarding and POP tab. In the Forwarding option, set Gmail to forward all incoming mail to your regular e-mail account, and keep a copy in Gmail's inbox.

(In this explanation, I will assume your regular e-mail address is user@domain.com and your Gmail address is user@gmail.com, and I apologize to Mr. User over at Domain.com and Mr. User over at Gmail if they get any extra mail from people following the steps in this article too literally.)

Once that forwarding rule is set on Gmail, all incoming mail to user@gmail.com will get spam filtered and anything left over will be forwarded to user@domain.com, with a copy left at Gmail. But that doesn’t help you much yet, because people are still sending spam directly to your user@domain.com account.

Now, over at your user@domain.com's mail server, create a server-side filter to check the headers of any incoming e-mail. Have it forward to your Gmail account if it does not find the following in the header:

X-Forwarded-For: user@gmail.com user@domain.com

In English, the filter would be written: "Any mail that does not contain 'X-Forwarded-For: user@gmail.com user@domain.com' in the mail header should be forwarded to user@gmail.com".

Once this server-side filter is in place, only mail on its way back from user@gmail.com (already filtered for spam) will be passed to your user@domain.com account's inbox. Everything else will be forwarded on to user@gmail.com to be filtered and forwarded back. "

Perhaps the issue is that you don't have the routing set up in your Gmail account, and that's why it's failing.

Also, your socket error:

"Socket Error #10060

The technical message behind this error is:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

You should ensure that:

* You have entered the correct IP address.
* The Agent is not behind a network firewall which is blocking the connection.
* The Agent is connected to the Internet.

Please Note: If the Agent is installed on Windows XP, you must make sure you have configured the built-in firewall to allow incoming connections on port 7250."

Hope that helps you out :)