Php Mail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
srirams
Forum Commoner
Posts: 36
Joined: Wed May 25, 2005 8:57 am
Location: India
Contact:

Php Mail

Post by srirams »

All,

If someone can help in this , it will be great.
I am trying to send mail from php using the below code.
<?php
$to = "sriram_s_98@yahoo.com";
$from = "sriram_s_98@yahoo.com";
$subject = "This is a test email";
$message = "Dear John,\n\nThis is a fake email, I hope you enjoy it.\n\nFrom Jane.";

$headers = "From: $from\r\n";

$success = mail($to, $subject, $message, $headers);
if ($success)
echo "The email to $to from $from was successfully sent";
else
echo "An error occurred when sending the email to $to from $from";
?>

I get the following error message.

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\program files\Apache Group\Apache2\htdocs\phpmail.php on line 9
An error occurred when sending the email to sriram_s_98@yahoo.com from sriram_s_98@yahoo.com

I am using windows XP client OS running on Apache webserver.
Can someone let me know where I am going wrong.

Regards
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

Your PHP has not been configured for any SMTP-server, you need to specify an SMTP-server (yours). this is commonly something specific to you/your service, and can sometimes be found in your mailsetup if you have gotten any.
srirams
Forum Commoner
Posts: 36
Joined: Wed May 25, 2005 8:57 am
Location: India
Contact:

Php Mail again

Post by srirams »

Thanks for the response.
But after I installed Argosoft mail I get this error in response.

Warning: mail() [function.mail]: SMTP server response: 551 User not local. We don't relay in C:\program files\Apache Group\Apache2\htdocs\phpmail.php on line 9
An error occurred when sending the email to sriram_s_98@yahoo.com from sriram_s_98@yahoo.com

What changes do I have to do in php.ini.
Also is there a way I can find out what is using my localhost address?
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

Post by batfastad »

You do not need to have an smtp server installed on your machine running PHP.
Even though we run exchange, I wouldn't dream of routing my nice PHP-generated email through exchange.

You can just use your ISPs SMTP server. The one you specify in outlook/express/eudora/thunderbird for when you send email, in your email account settings.

To tell PHP to use your ISPs mail server, do the following...

In php.ini search for the text [mail function]

Code: Select all

&#1111;mail function]
; For Win32 only.
SMTP = smtp.isp.com
smtp_port = 25

; For Win32 only.
sendmail_from = administrator@domain.com

; For Unix only.  You may supply arguments as well (default: &quote;sendmail -t -i&quote;).
;sendmail_path =
That's the bit in my php.ini on windows 2000.

Remove the semi-colon in front of the SMTP = and smtp_port = values.
And change smtp.isp.com to whatever your ISPs smtp/outgoing mail server is.

Then change sendmail_from = to whatever email address you want emails sent using mail() to appear as if they're sent from.
Note that if you specify a different 'From: ' header in the mail() function, then that will override the sendmail_from variable in php.ini

So there's only two little changes you need to make in php.ini to get it working.

HTH

Batfastad
Post Reply