...

View Full Version : Sending Email



soccer022483
07-17-2004, 11:05 PM
Ok this should be an easy question to answer. I have a domain name www.anova-design.com. I'm very good with web design, but I'm new to php and it's driving me crazy! Haha, anyways I'm trying to send an email using a form. This is what I have so far...

email.php:

<form action="send.php" method="post"><table border="1" cellspacing="0" cellpadding="1">
<tr>
<td>Name:</td>
<td><input name="Name" type="text" id="Name"></td>
</tr>
<tr>
<td height="23">Email:</td>
<td><input name="Email" type="text" id="Email"></td>
</tr>
<tr>
<td height="23">Subject:</td>
<td><input name="Subject" type="text" id="Subject"></td>
</tr>
<tr>
<td height="23">Comments</td>
<td><textarea name="textarea" wrap="VIRTUAL"></textarea></td>
</tr>
<tr>
<td height="23"><input name="Submit" type="submit" id="Submit" value="Send"></td>
<td>&nbsp;</td>
</tr>
</table>
</form>

send.php:
<?php
$to = "soccer022483@comcast.net";
$name = $_POST['Name'];
$from = $_POST['Email'];
$subject = $_POST['Subject'];
$comment= $_POST['Comments'];
$message = "$comment \n\n From,\n\n $name \n\n";
$headers = "From: $from\r\n";

$success = mail($to, $subject, $message, $headers);
if ($success)
echo "The email to $to from $from was successfully sent";
else
echo "The Must be an Error on the Page that you have sent us Please go back and Try agian to $to from $from";
?>

Ok those are the two files. When I upload them and go to www.anova-design.com/email.php it comes up fine. When I test it out and try to send the email to my self I never receive it. I know my host is php enabled. Can anyone help me out??

Austin

circusbred
07-18-2004, 03:34 AM
You're only checking if the variable "success" is not null, since its not null, you get the success message, try:



<?php
$to = "soccer022483@comcast.net";
$name = $_POST['Name'];
$from = $_POST['Email'];
$subject = $_POST['Subject'];
$comment= $_POST['Comments'];
$message = "$comment \n\n From,\n\n $name \n\n";
$headers = "From: $from\r\n";

if ($name && $from && subject && comment) { // make sure these fields arent null
echo "The email to $to from $from was successfully sent";
mail($to, $subject, $message, $headers);
} else {
echo "The Must be an Error on the Page that you have sent us Please go back and Try agian to $to from $from";
}
?>

soccer022483
07-18-2004, 06:23 PM
Yeah but even with my code it says the mail was successfully sent. I didn't come up with this code I got it off a site somewhere that says it works (who knows). I still should be receiving the email regardless. I don't think it's a problem with the code but maybe my host, or maybe I don't have something set up right, I have no idea.

raf
07-18-2004, 07:00 PM
You're only checking if the variable "success" is not null, since its not null, you get the success message,
actually, that is not correct. Mail returns a boolean (False or True) so his initial

if ($success)
echo "The email to $to from $from was successfully sent";

is just fine.

Your code on the other hand is buggy and contains the logical error that you would print the message before even executing the mail() ! Your statusmessage doesn't check the outcome of the mail-action.


soccer022483, try it with another mailadress or else contact your host.

soccer022483
07-18-2004, 10:34 PM
Ok. Thanks for the help you guys.

Austin



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum