Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Help Please !!!

the mail() function

Moderators: macek, egami, gesf

Help Please !!!

Postby sriram » Thu May 13, 2004 12:55 pm

I'm new to this PHP. I donno anything about PHP.I'm a college student and i've a assignment to complete.If possible, can i get the complete code.
I'm a college student and i've to put up a form on my college site such that the mail is sent to their <admission number>@collegesitename.com
Here the there are 3 college domain like college.com ,college.net , college.edu
Admission numbers starting from 4NI00XXXXXX to 4NI01XXXXXX are given email address in college.com domain. And 4NI02XXXXXX to 4NI03XXXXXX are given the email address in college.net domain and so on.
now what i want to do is put 4NI00,4NI01,4NI02,4NI03 in a drop down menu and when they want to send a email if they select 4NI00 the mail should go to that particular domain.In between there should be a text box where they enter the remainin part of their ADMISSION NUMBER.( i.e XXXXXX)
So email should go to: 4NI00<text entered>@<particular domain name>
The FROM email ID is constant i.e its fixed to somethin like <admin@college.com>Please can anybody help me.
The form should be somethin like below:

Admission No : [4NI00] [XXXXXX]
Sender Name: [--------------]
Message: [-------------------------
-------------------------
-------------------------
-------------------------]
{Send Mail} {Clear}
sriram
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu May 13, 2004 12:31 pm

Re: Help Please !!!

Postby swirlee » Thu May 13, 2004 1:32 pm

sriram wrote:I'm a college student and i've a assignment to complete.If possible, can i get the complete code.


No. We're not here to do your assignments for you.

This is pretty basic PHP. I recommend you read the beginning tutorial and the first few chapters of the manual at the official site and, if possible, pick up a good PHP book at your local bookstore.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby sriram » Thu May 13, 2004 2:04 pm

Hi Pal,
Thanks pal for such a RUDE reply.I've already done what u told.I've written the script,but it has got some errors.Can't make out where.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<?php

$this_file = $_SERVER['PHP_SELF'];

switch ($_GET['id'])
{

# Firstly we find if the person has filled in the form and wants to send

case "postmail":

switch ($_POST['admin_number'])
{

# Depending on which Admission Number they chose, select the appropriate domain

case "4ni00": $domain = "college.com"; break;
case "4ni01": $domain = "college.net"; break;
case "4ni02": $domain = "college.edu"; break;
case "4ni03": $domain = "college.edu"; break;

}

# Gather all the information into handy variables

# Send the message to the admin number @ the selected domain

$to = $_POST['admin_number'] . $_POST['admin_number_2'] . "@" . $domain;

# Set the from e-mail as the sender name, sendername@college.com

$from = "From: \"" .$_POST['sender_name']. "\" <" .$_POST['sender_name']. "@college.com>";

# Store the subject in the subject variable

$subject = $_POST['subject'];

# Store the message in the message variable

$message = $_POST['message'];

# Check to see whether the message sent successfully

if (mail($to,$subject,$message,$from))

{

# If it did, tell the user it was sent and redirect them back to the form

echo "<center><font size=\"1\">";
echo "Your message has been sent to its destination<br>Please wait while you are re-directed to the main page.";
echo "<meta content=\"2; url=" .$_SERVER['PHP_SELF']. "\" http-equiv=\"refresh\">";
echo "</font></center>";

}
else
{

# If it failed, tell the user it failed and redirect them back to the form

echo "<center><font size=\"1\">";
echo "Your message has failed to send to its destination<br>Please wait while you are re-directed to the main page.";
echo "<meta content=\"2; url=" .$_SERVER['PHP_SELF']. "\" http-equiv=\"refresh\">";
echo "</font></center>";

}


break;

# If the user has not already filled in the form, present the form for them

default:
?>


<form name="form1" method="post" action="<?php echo $this_file . "?id=post" ?>">
Adminision Number:
<select name="admin_number">
<option value="4ni00">4NI00</option>
<option value="4ni01">4NI01</option>
<option value="4ni02">4NI02</option>
<option value="4ni03">4NI03</option>
</select>
<input name="admin_number_2" type="text" id="admin_no">
<br>
<br>
Sender Name:
<input name="sender_name" type="text" id="sender_name">
<br>
<br>
Subject:
<input name="subject" type="text" id="subject">
<br>
<br>
Message:<br>
<textarea name="message" cols="45" rows="7" id="message"></textarea>
<br>
<br>
<input type="submit" name="Submit" value="Send Message">
</form>

<?php break; } ?>

</body>
</html>


Anybody can help me in making this script work
sriram
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu May 13, 2004 12:31 pm

Postby swirlee » Thu May 13, 2004 2:34 pm

A rude question like "please write my code for me" doesn't deserve a polite answer. Now, if you'd told us to begin with that you'd already written some code, and posted it, things would be different.

Now then, if you've got errors, you need to past them here, along with what lines they refer to.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron