Welcome to Gaia! ::


I'm having trouble getting my mailing form to work sweatdrop

My html form is:
<form method="post" action="sendmail.php">
<p>Name:
<br>
<input name="name" type="text" class="field"/>
</p>
<p>Email:
<br>
<input name="email" type="text" class="field"/>
</p>
<p>Subject:<br>
<input name="subject" type="text" class="field"/>
</p>
<p>Message:<br />
<textarea name="message" rows="8" cols="30" class="field">
</textarea>
<br />
<input name="submit" type="submit" id="submit" value="send" class="button"/>
<input name="reset" type="reset" id="reset" value="reset" class="button"/>
</p>
</form>


And the sendmail.php contains:
<?
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;

mail('yarnyeetong@gmail.com',$subject,$text,"From: $name <$email>")
header("location:form.php")
?>


This is all pretty much posted from a tutorial, and I've checked with other online tutorials, and kind figure out what I'm doing wrong. Any suggestions?
I'm not a php guru, but I'll have a crack at it.

Your code all looks good, but looking at the php reference for mail() and I found some things out.
Quote:
The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

So it looks like you'll have difficulties running this on a Windows server as opposed to a *nix one. If you're on a Windows server, you'll need to go about it a different way. xp

I'll be gone today, but maybe someone else can help you if that's the case. sweatdrop

Rannos
Chisa
I'm having trouble getting my mailing form to work sweatdrop

My html form is:
<form method="post" action="sendmail.php">
<p>Name:
<br>
<input name="name" type="text" class="field"/>
</p>
<p>Email:
<br>
<input name="email" type="text" class="field"/>
</p>
<p>Subject:<br>
<input name="subject" type="text" class="field"/>
</p>
<p>Message:<br />
<textarea name="message" rows="8" cols="30" class="field">
</textarea>
<br />
<input name="submit" type="submit" id="submit" value="send" class="button"/>
<input name="reset" type="reset" id="reset" value="reset" class="button"/>
</p>
</form>


And the sendmail.php contains:
<?
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;

mail('yarnyeetong@gmail.com',$subject,$text,"From: $name <$email>")
header("location:form.php")
?>


This is all pretty much posted from a tutorial, and I've checked with other online tutorials, and kind figure out what I'm doing wrong. Any suggestions?
what error do you get??

also try putting the mail funtion into an if to test it {mail returns true on sucsess and false on error}
Rannos
I'm not a php guru, but I'll have a crack at it.

Your code all looks good, but looking at the php reference for mail() and I found some things out.
Quote:
The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

So it looks like you'll have difficulties running this on a Windows server as opposed to a *nix one. If you're on a Windows server, you'll need to go about it a different way. xp

I'll be gone today, but maybe someone else can help you if that's the case. sweatdrop

Rannos


Basically what it means is on windows you need to run a mail server, you can find many of them on download.com. I'd suggest blocking the incoming smtp port from the internet tho ;P

As for the code, I'm not experienced enough in php to say anything about that.
try this for your php script and see if it works. I've also included it validating the email address and forcing the user to fill in the name, email, and message fields.


<?php

if ($email=="" || $message=="" || $name=="")
{
echo "Blank submission or you didn't fill in some fields. Go back.";
}

else {

if(!eregi('^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3})?)$', $email)) {

echo "That does not look like a valid email address, please re-enter.";

exit;

}

$youremail="yarnyeetong@gmail.com";
$headers = "From: \"$name\" <$email>\n";
$subject="$subject";
$message = "$message";


mail("$youremail", "$subject", $message, $headers)

echo "Thank you $name, your email has been sent.";

}
?>


also, try naming the script formmail.php instead of sendmail.php I don't know if it'll make a difference, but it's what I've always used
Rannos - I'm not sure if my server is Windows based or *nix based xp

grundal - I don't get any error, I just don't receive the email

AkaiTsuki - ... I have absolutely no idea what most of that means. Damn I'm a pathetic Comp Sci student sweatdrop

Washable_Marker - works perfectly with your code, thanks so much! And thanks for the form validation too, I hadn't got around to doing that yet. It works fine as sendmail.php, the file name shouldnt matter.

Thanks everyone!

Quick Reply

Submit
Manage Your Items
Other Stuff
Get GCash
Offers
Get Items
More Items
Where Everyone Hangs Out
Other Community Areas
Virtual Spaces
Fun Stuff
Gaia's Games
Mini-Games
Play with GCash
Play with Platinum