Page 1 of 1

How to send an email in PHP?

Posted: Mon Dec 08, 2008 2:59 pm
by rjuy
I have this following code, but the time I run this code on my browser...

it has an warning ang error saying


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:\wamp\www\New Folder\index.php on line 8
Mail Sent.



what shoud i do?

i uploaded the code asa well....

thanks

-rjuy


<?php

$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<html>
<body>

</body>
</html>

Re: How to send an email in PHP?

Posted: Mon Dec 08, 2008 3:04 pm
by jaoudestudios
what server are you running?

I bet I can guess...windows?!? If so you do not have a mailserver, so the email can not be sent :)

Re: How to send an email in PHP?

Posted: Mon Dec 08, 2008 3:05 pm
by rjuy
yes, i'm using windows....


thanks

i'll try this one

-rjuy

Re: How to send an email in PHP?

Posted: Mon Dec 08, 2008 3:07 pm
by rjuy
how can i have a mailserver then in my sytem?

thanks

Re: How to send an email in PHP?

Posted: Tue Dec 09, 2008 1:43 am
by jaoudestudios
I tried a while ago on windows many times and failed. So in the end I installed Linux Fedora and that had everything installed by default.

You can setup your apache (WAMP) to connect to a remote SMTP.

Re: How to send an email in PHP?

Posted: Tue Dec 09, 2008 1:54 am
by zhaolei254
If you don't have smtp server !
Need socket!!

Re: How to send an email in PHP?

Posted: Tue Dec 09, 2008 8:33 am
by rjuy
You can setup your apache (WAMP) to connect to a remote SMTP. how?

i dont have any idea... Sorry..

Thanks,,

-rjuy

Re: How to send an email in PHP?

Posted: Tue Dec 09, 2008 8:36 am
by papa
1. Google wamp
2. Install
3. Send email(s)

Re: How to send an email in PHP?

Posted: Tue Dec 09, 2008 12:49 pm
by jaoudestudios
In the httpd.conf file about half way down you will see the stmp details. Modify it to your remote smtp. Then restart apache.

Re: How to send an email in PHP?

Posted: Tue Dec 09, 2008 1:31 pm
by rjuy
where is that? very sorry such a noobs here....

I really feel sorry for my self... New to web developement, and accept the fact that i'm not so good in configuration...

thanks,

-rjuy

Re: How to send an email in PHP?

Posted: Tue Dec 09, 2008 1:44 pm
by jmut
Don't feel sorry, but don't ask every detail either..... rarely someone will tell you exactly what todo step by step just like that. Show some willling and read some docs. I suggest you save some time and directly use http://swiftmailer.org/ There are examples ect...howto connect to server and so on.
Try out read and let us know how it goes.

Re: How to send an email in PHP?

Posted: Tue Dec 09, 2008 1:59 pm
by rjuy
thank u very much

-rjuy