How to send an email in PHP?

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
rjuy
Forum Newbie
Posts: 15
Joined: Thu Apr 17, 2008 4:56 am

How to send an email in PHP?

Post 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>
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: How to send an email in PHP?

Post 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 :)
rjuy
Forum Newbie
Posts: 15
Joined: Thu Apr 17, 2008 4:56 am

Re: How to send an email in PHP?

Post by rjuy »

yes, i'm using windows....


thanks

i'll try this one

-rjuy
rjuy
Forum Newbie
Posts: 15
Joined: Thu Apr 17, 2008 4:56 am

Re: How to send an email in PHP?

Post by rjuy »

how can i have a mailserver then in my sytem?

thanks
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: How to send an email in PHP?

Post 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.
User avatar
zhaolei254
Forum Newbie
Posts: 1
Joined: Mon Dec 08, 2008 10:52 pm

Re: How to send an email in PHP?

Post by zhaolei254 »

If you don't have smtp server !
Need socket!!
rjuy
Forum Newbie
Posts: 15
Joined: Thu Apr 17, 2008 4:56 am

Re: How to send an email in PHP?

Post by rjuy »

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

i dont have any idea... Sorry..

Thanks,,

-rjuy
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: How to send an email in PHP?

Post by papa »

1. Google wamp
2. Install
3. Send email(s)
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: How to send an email in PHP?

Post 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.
rjuy
Forum Newbie
Posts: 15
Joined: Thu Apr 17, 2008 4:56 am

Re: How to send an email in PHP?

Post 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
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: How to send an email in PHP?

Post 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.
rjuy
Forum Newbie
Posts: 15
Joined: Thu Apr 17, 2008 4:56 am

Re: How to send an email in PHP?

Post by rjuy »

thank u very much

-rjuy
Post Reply