Page 1 of 1
sending email automaticlly...........
Posted: Tue Oct 28, 2003 5:21 pm
by gavinbsocom
Im trying to send an email from a form automaticlly, when the person clicks join, i want it to just send it to me, i dont want it to open up an email service ont here screen...What i stated to do isnt working, maybe a point in the right direction would be great, Im sor tof stuck...
Join.php (not full page just the form)
________________________________________________
Code: Select all
<form method="get" action="mail.php">
<tr><td class="join">Real Name : <input type="text" name="text"></td></tr>
<tr><td class="join">SOCOM name : <input type="text"></td></tr>
<tr><td class="join">e-Mail address : <input type="text"></td></tr>
<tr><td class="join">Aim Name : <input type="text"></td></tr>
<tr><td class="join">language(s) you speak: <input type="text"></td></tr>
<tr><td class="join">Your time zone : <input type="text"></td></tr>
<tr><td class="join">Channel you play in : <input type="text"></td></tr>
<tr><td class="join">When you Started Playing : <input type="text"></td></tr>
<tr><td class="join">Previous clan experience(s) : <input type="text"></td></tr>
<tr><td class="join">Desired A\* user name : <input type="text"></td></tr>
<tr><td class="join">Comments : <textarea rows="3" cols="30"></textarea></td></tr>
<tr><td> </td></tr>
<tr><td align="center"><input type="submit" value="Submit"> <input type="reset"></td></tr>
</form>
Mail.php ( full page just the mail function, not sure if i have it right)
__________________________________________________
Code: Select all
<html>
<body>
<?php
$to = "Gavin<gavinbsocom@hotmail.com>";
$subject = "test";
$body = "something";
$from = "From: Me <gavinbsocom@hotmail.com>\n";
$cc = "Cc: Dude<gavinbsocom@hotmail.com>\n";
$bcc = "Bcc: Ghost<gavinbsocom@hotmail.com>\n";
$headers = $from . $cc . $bcc;
mail($to, $subject, $body, $headers);
?>
</bodY>
</html>
Also what does the cc and bcc do for you? what do they stand for? do i need them?
Posted: Tue Oct 28, 2003 5:47 pm
by qads
do you get any error mssages?
where is the NAME part ^^^^, lot of your fields are missing that.
Re: sending email automaticlly...........
Posted: Tue Oct 28, 2003 6:11 pm
by DuFF
gavinbsocom wrote:Also what does the cc and bcc do for you? what do they stand for? do i need them?
I agree with the above message, right now the form is not interacting with the email page at all. If the fields have no names then the script doesn't know what they are called. You want to do something like this:
Code: Select all
<input type="text" name="realname">
then in mail.php have
Code: Select all
$body = "Realname: $realname";
$body .= "Aim Name: $aimname";
Also, Bcc Stands for Blind Carbon Copy. You can send a copy of an email to other people by entering their email addresses in this field. The person that you send the email listed in the To Field will not see these other addresses. The Cc ( Carbon Copy) field is a little different, any addresses you put in the Cc field will be seen by the person listed in the To field. No you don't need them.
Posted: Tue Oct 28, 2003 6:12 pm
by d3ad1ysp0rk
currently it should send you an email saying "test"
to get it to send their info, you'll need to name each variable, then do something like
Code: Select all
$body = $name + "\n\r" + $sname + "\n\r" + $email;
etc...
Posted: Tue Oct 28, 2003 6:22 pm
by Gen-ik
First things first... your form would probably be happier if you used METHOD="POST" instead of "GET". GET is ok for small text (the variables get added to the url) but POST is always your best bet.
Your form <inputs> don't have any names. If you want PHP to use any info from a form you need to give your <inputs> names.
The CC and BCC are just standard email options and you don't really need to use them.
Try the following and see if it works.......
FORM PAGE
Code: Select all
<html>
<body>
<form method="post" action="mail.php">
TO : <input type="text" name="to" value="email@address"><br>
SUBJECT : <input type="text" name="subject" value=""><br>
MESSAGE : <textarea name="message" rows="6" cols="40"></textarea><br>
FROM : <input type="text" name="from" value="email@address"><br><br>
<input type="submit" value="Send Email">
</form>
</body>
</html>
MAIL.PHP PAGE
Code: Select all
<?
$to = $_POST["to"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$from = $_POST["from"];
$has_been_sent = mail($to, $subject, $message, $from);
if($has_been_sent)
{
echo "Email sent.";
}
else
{
echo "Email failed.";
}
?>
Posted: Tue Oct 28, 2003 10:25 pm
by gavinbsocom
wow alot of great information, I learned alot, thankyou. Gen-ik thankyou i have been playing around with what you posted and it works great !
Posted: Tue Oct 28, 2003 10:30 pm
by gavinbsocom
one thing i dont understatnd gen-ik is how the it sends the email, how does it choose where it goes? by the $to ? its a little confusing?
Posted: Tue Oct 28, 2003 11:20 pm
by phice
$to = the variable, given in the form in the previous php document, set to the location in which the email will be sent to.
Posted: Wed Oct 29, 2003 12:03 am
by gavinbsocom
k now i got a little more updated as far as looks go, but i also changed the part on the mail.php file, but the last else doesnt work?
Join.php
____________________________________________________
Code: Select all
<form method="post" action="mail.php">
<tr><td class="join">TO : <input type="text" name="to" value="russian@bniclan.com"></td></tr>
<tr><td class="join">SUBJECT : <input type="text" name="subject" value=""></td></tr>
<tr><td class="join">MESSAGE : <textarea name="message" rows="6" cols="40">
Socom Name :
Real Name :
Aim Name :
Email Address :
Time Zone :
</textarea></td></tr>
<tr><td class="join">FROM : <input type="text" name="from" value="email@address"></td></tr>
<tr><td> </td></tr>
<tr><td class="join" align="center"><input type="submit" value="Send Email"></td></tr>
<tr><td> </td></tr>
<tr><td class="join" align="center"><input type="reset"></td></tr>
<tr><td> </td></tr>
</form>
mail.php
_____________________________________________________
Code: Select all
<?php
$complete = "Email Sent !";
if($has_been_sent)
{
echo "$complete";
}
elseif($complete)
{
header('location:http://www.bniclan.com');
}
else
{
echo "Email Failed.";
}
?>
<html>
<body>
<?php
$to = $_POSTї"to"];
$subject = $_POSTї"subject"];
$message = $_POSTї"message"];
$from = $_POSTї"from"];
$has_been_sent = mail($to, $subject, $message, $from);
?>
</bodY>
</html>
if you want to see it in action go to
http://www.bniclan.com/join.php ...The problem is it always refreshes back to the home page(
http://www.bniclan.com) I want the error to work also, so if the error works it should say Email Failed !
Posted: Wed Oct 29, 2003 12:37 pm
by phice
The last else will never work when you have the variable set at the top of the page. When you set a variable, and do an if($variable) on it, it'll always show up.
Posted: Wed Oct 29, 2003 12:54 pm
by gite_ashish
... like ....
<?php
$to = $_POST["to"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$from = $_POST["from"];
$has_been_sent = mail($to, $subject, $message, $from);
?>
<html>
<body>
<?php
$complete = "Email Sent !";
if($has_been_sent)
{
echo "$complete";
}
elseif($complete)
{
header('location:
http://www.bniclan.com');
}
else
{
echo "Email Failed.";
}
?>
</bodY>
</html>
Posted: Wed Oct 29, 2003 12:57 pm
by gite_ashish
i guess, you r looking for something like --
<?php
$complete = "Email Sent !";
if($has_been_sent) // mail sent SUCESSFULLY, so redirect to home page...
{
echo "$complete";
header('location:
http://www.bniclan.com');
}
else // mail sent FAILED, show error and stop...
{
echo "Email Failed.";
}
?>
Posted: Wed Oct 29, 2003 5:21 pm
by gavinbsocom
i tried that already, the only thing that happens is the header is not executed and it always puts email failed. and thats all it says ? any suggestions?
Posted: Wed Oct 29, 2003 6:42 pm
by Gen-ik
FORM FOLLOWS FUNCTION. This is a good way of creating anything web based. It means get everything working first, and then add all of the nice graphics and stuff afterwards.
Go back to the point where your email form was working and then add new code bit by bit. If the new changes don't work then figure out why before moving on to the next thing.
Don't worry about how good it looks until the back-end stuff is working.