These are the steps in registering a new user.

1. A new user is registered (provide name, address, email etc.)
2. An email is sent to the email he/she provided, which contains his login information.

the problem now is the emial code. I've never done this before so I don't know how this works. I tried searching for help, and the acronym SMTP always pops up. and I don't know how that works either. I know I have to configure php.ini to be able to do this, but I don't know what to change.

here's a sample code i got from the net. I'm trying to make this work first.

$email_to = "";
$email_subject = "Test E-Mail (This is the subject of the E-Mail)";
$email_body = "This is the body of the Email \nThis is a second line in the body!";

if(mail($email_to, $email_subject, $email_body)){
echo "The email($email_subject) was successfully sent.";
} else {
echo "The email($email_subject) was NOT sent.";

Please Help me.

Recommended Answers

All 10 Replies

First off, a really good tutorial website would be They have alot of different things you can learn. Thats where i got my email code. Most mail servers require a SMPT in order to find it, its like have a website but with no DNS lookup.
So a real simple one to start would be (from

// i just googled these
// if you need authorization
$to = "";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "";
$headers = "From: $from";
echo "Mail Sent.";

I hope this helps out.

I have just changed this part of php.ini and it works for me.
Check it out.

[mail function]
; For Win32 only.
SMTP = // smtp mail server name
smtp_port = 25

Member Avatar

Yeah, the only changes we need in php.ini, but for different scenarios the thing is also different.

Thank you for your help but this error is generated when i changed my SMTP.

Warning: mail() [function.mail]: Failed to connect to mailserver at "" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

i don't know if i'm assigning the right data to the SMTP. where can i find the correct data to assign to it?

I need to know the right SMTP value so i can continue with the tutorial from w3 and from the article you gave. Thank you.

Member Avatar

You are the right place now. You script will work if you tested on you server by loading your files in ftp.

so it's not working coz it's running in localhost?

our site is down at the moment. I'll try to test it when it's up and running again.

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

; For Win32 only.
;sendmail_from =

is that the correct thing to do in the php.ini? i mean is the SMTP value correct already?

and here's the code i got from the net.


if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  //send email
  $email = $_REQUEST['email'] ;
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  mail( "", "Subject: $subject",
  $message, "From: $email" );
  echo "Thank you for using our mail form";
//if "email" is not filled out, display the form
  echo "<form method='post' action='mailform.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />


that's for email.php

  $email = $_POST['email'] ;
  $subject = $_POST['subject'] ;
  $message = $_POST['message'] ;
  mail( "", "Subject: $subject", $message, "From: $email" );
  echo "Thank you!";

and that's for mailform.php

do you think these codes will be alright when uploaded to the net?

Member Avatar

Yahoo Outgoing Mail Server (SMTP) - (port 25)

i already change it to that. now i'll just wait if it'll work. i hope it works T.T

Thank you :) I hope you'll still help me when if i get errors by the time i upload this

Member Avatar


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.