Web Hosting Talk







View Full Version : PHP - Sending An Email


ballingtonma
02-01-2004, 06:09 PM
I am trying to set a PHP form whereby useres can send emails to anyone they like. Here is the script:

The Form:
<form name="form" method="post" action="send.php">
<table width="400" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="200" valign="top" align="right">What Email To Send To: </td>
<td width="200" valign="top" align="left">
<input type="text" name="mailto" size="25" maxlength="200" />
</td>
<tr>
<td width="200" valign="top" align="right">Msg Subject: </td>
<td width="200" valign="top" align="left">
<input type="text" name="mailsub" size="25" maxlength="200" />
</td>
<tr>
<td width="200" valign="top" align="right">Your Name: </td>
<td width="200" valign="top" align="left">
<input type="text" name="name" size="25" maxlength="200" />
</td>
</tr>
<tr>
<td width="200" valign="top" align="right">Your Email:</td>
<td width="200" valign="top" align="left">
<input type="text" name="email" size="25" maxlength="100" />
</td>
</tr>
<tr>
<td width="200" valign="top" align="right">Your Comments: </td>
<td width="200" valign="top" align="left">
<textarea name="msg" cols="25" rows="4"></textarea>
</td>
</tr>
<tr>
<td width="200" valign="top">&nbsp;</td>
<td width="200" valign="top" align="left">
<input type="reset" name="Reset" value="Reset" />
<input type="submit" name="Submit" value="Submit" />
</td>
</tr>
</table>
</form>

And The PHP Action page:
<?
$headers .= "From: $name <$email>\n";
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
$recipient = "$mailto";
$subject = "$mailsub";
$msg = wordwrap( $msg, 1024 );

mail($recipient, $subject, stripslashes($msg), $headers);

header("location: sent.php");
?>

And The Sent Page:
<p align="center"><h1>Msg Sent</h1>The Email Has Now Been Sent To <? echo "$recipient"; ?></p>

This isnt working for some reason so I was hoping someone could help me get it working.

Thanks in advance,
Matt

Loon
02-01-2004, 06:15 PM
What exactly happens? do you get errors? or it just isn't sent? or something else?

If register_globals are not enabled you would need to get your values from the form with $_POST['value'];

Also in your confirm page you need to echo or print the recipient although that wouldn't stop it working.

If you get errors please post them, from a quick look over it seems ok.

ballingtonma
02-01-2004, 06:20 PM
I dont get any errors, the email just isnt sent.

ballingtonma
02-01-2004, 06:56 PM
I made a new send page just to see if the page is able to recive the information, and it is.
The Experiment Send Page<?
echo "
From: $name <$email>
Recipient: $mailto
Subject: $mailsub
MSG: $msg
";
?>

So, why can it not send this information in the email?

Tagban
02-01-2004, 07:09 PM
Thank you!! I'll actually use that ^^

Rich2k
02-01-2004, 07:46 PM
The use of the Location header is possibly supressing any errors you may have sending. Try removing the header() function until you have it working.

On a side note I really, really wouldn't put a script like that on a public website that anyone can use.... the likelyhood of it being used for spam is high and then you'll loose your hosting account.

ballingtonma
02-02-2004, 12:14 PM
I havent made any changes to it, but now it works, abd sometimes, no email is sent. Im not sure why this is, is it possible that there is a limit to messages sent like this that is set by my host?
Also, does anyone know how i could make a script so that, somone could only send like 2 emails an hour (two different people only). I am aware this could be done with cookies, but people could just delete them, so is it possible using the users ip address in a flat file?


Thanks,
Matt

kneuf
02-02-2004, 05:10 PM
I know that Hotmail, and maybe AOL, have problems with recieving emails. Also, if your domain/IP is on a 'blacklist' (can't remember the name), then a lot of major email hosting companies won't accept your mail. And yes, the IP in a flat file DB would probably work.