sending email automaticlly...........

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
gavinbsocom
Forum Commoner
Posts: 71
Joined: Tue Sep 30, 2003 9:51 pm

sending email automaticlly...........

Post 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>&nbsp;</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?
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

do you get any error mssages?

Code: Select all

<input type="text">
where is the NAME part ^^^^, lot of your fields are missing that.

Code: Select all

<input type="text" name="bla">
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Re: sending email automaticlly...........

Post 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.
Last edited by DuFF on Tue Oct 28, 2003 6:17 pm, edited 2 times in total.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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...
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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

&lt;html&gt;
&lt;body&gt;

&lt;form method="post" action="mail.php"&gt;
TO : &lt;input type="text" name="to" value="email@address"&gt;&lt;br&gt;
SUBJECT : &lt;input type="text" name="subject" value=""&gt;&lt;br&gt;
MESSAGE : &lt;textarea name="message" rows="6" cols="40"&gt;&lt;/textarea&gt;&lt;br&gt;
FROM : &lt;input type="text" name="from" value="email@address"&gt;&lt;br&gt;&lt;br&gt;
&lt;input type="submit" value="Send Email"&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

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.";
}

?>
gavinbsocom
Forum Commoner
Posts: 71
Joined: Tue Sep 30, 2003 9:51 pm

Post 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 !
gavinbsocom
Forum Commoner
Posts: 71
Joined: Tue Sep 30, 2003 9:51 pm

Post 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?
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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.
Image Image
gavinbsocom
Forum Commoner
Posts: 71
Joined: Tue Sep 30, 2003 9:51 pm

Post 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>&nbsp;</td></tr>
<tr><td class="join" align="center"><input type="submit" value="Send Email"></td></tr>
<tr><td>&nbsp;</td></tr>
<tr><td class="join" align="center"><input type="reset"></td></tr>
	<tr><td>&nbsp;</td></tr>
</form>

mail.php
_____________________________________________________

Code: Select all

<?php

$complete = "Email Sent !";

if($has_been_sent) 
  &#123; 
  echo "$complete";
  &#125;
    elseif($complete)
    &#123;
    header('location:http://www.bniclan.com');
    &#125;
      else
      &#123; 
      echo "Email Failed."; 
      &#125; 

?>
<html>
<body>

<?php

$to = $_POST&#1111;"to"]; 
$subject = $_POST&#1111;"subject"]; 
$message = $_POST&#1111;"message"]; 
$from = $_POST&#1111;"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 !
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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.
Image Image
User avatar
gite_ashish
Forum Contributor
Posts: 118
Joined: Sat Aug 31, 2002 11:38 am
Location: India

Post 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>
User avatar
gite_ashish
Forum Contributor
Posts: 118
Joined: Sat Aug 31, 2002 11:38 am
Location: India

Post 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.";
}

?>
gavinbsocom
Forum Commoner
Posts: 71
Joined: Tue Sep 30, 2003 9:51 pm

Post 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?
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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.
Post Reply