Trying to make a kind of submission form, don't want to use "action="mailto:...."" but I want a script to just e-mail me the contents.
Preferably PHP, could anyone show me an example of one (or even flesh one out for me)
Cheers
Trying to make a kind of submission form, don't want to use "action="mailto:...."" but I want a script to just e-mail me the contents.
Preferably PHP, could anyone show me an example of one (or even flesh one out for me)
Cheers
PHP Code:
<?php
//email address
$contact_emails = array(
array('webmaster@example.net', 'Webmaster 1'),
array('sales@example.net', 'Sales 2'),
);
if(!$action)
{
echo "Contact Us\n";
echo "\n";
echo "<form action='contact.php?action=send' method='post'>\n";
echo "Person to Contact:\n";
$list = '<select name="contact">';
foreach($contact_emails as $key=>$value) {
$list .= '<option value="'. $key .'">'. $value[1] .'</option>';
}
$list .= '</select>';
echo $list;
echo "<br>\n";
echo "Full Name: <input type='text' name='name'>\n";
echo "Email Address:> <input type='text' name='email'><br>\n";
echo "Message:\n";
echo "<br><textarea name='msg' cols='30' rows='5'></textarea>\n";
echo "<br><input type='submit' name='submit' value='Contact me'>";
}
elseif($action==send)
{
if(!$_POST[name])
{
print("ERROR: Please enter name field<br>");
}
if(!$_POST[email])
{
print("ERROR: Please enter email field<br>");
}
if(!$_POST[msg])
{
print("ERROR: Please enter message field<br>");
}
elseif(($_POST[name])&&($_POST[email])&&($_POST[msg])==!NULL)
{
print("Message sent,Thank you!");
$re = "Online Contact Form";
$msg = "FROM: $_POST[name]
$_POST[msg]";
$headers .= "From: $_POST[email] \r\n";
$myemail = $contact_emails[$_POST['contact']][0];
mail($myemail,$re,$msg, $headers);
}
}
?>
Last edited by Barry; 05-12-2004 at 11:34 PM.
Someone left a note on a piece of cake in the fridge that said, "Do not eat!". I ate the cake and left a note saying, "Yuck, who the hell eats paper ?
I haven't had a chance to properly look at the code but a few tips
- you don't need a separate echo for every line
- it is better to enclose echo statements in single quote unless you are creating a SQL query as it's faster for PHP to parse
- HTML parameters should be enclosed in double quotes to comply with W3C guidelines, not single quotes
- Close tags to make it XHMTL compliant e.g. <br> should be <br />
- No need for two arrays, use the key and value
- Don't echo your success message until you've actually sent the mail !
So you could end up with
The best way to do this is via a class. I can recommend phpmailer as a useful optionPHP Code:
<?php
//email address
$contact_emails = array(
'webmaster@example.net' => 'Webmaster 1',
'sales@example.net' => 'Sales 2');
if(!$action)
{
echo 'Contact Us\n\n
<form action="contact.php?action=send" method="post">\n
Person to Contact:\n
<select name="contact">';
foreach($contact_emails as $key => $value)
{
echo '<option value="'. $key .'">'. $value .'</option>';
}
echo '</select>
<br />\n
Full Name: <input type="text" name="name">\n
Email Address: <input type="text" name="email"><br>\n
Message:\n
<br /><textarea name="msg" cols="30" rows="5"></textarea>\n
<br /><input type="submit" name="submit" value="Contact me">';
} elseif($action=='send') {
$fields = array('name'=>'name', 'email'=>'email', 'msg'=>'message');
$errorFound = 'no';
foreach ($fields as $key => $value)
{
if (!$_POST[$key])
{
echo 'ERROR: Please enter '.$value.' field<br />';
$errorFound = 'yes';
}
}
if ($errorFound == 'no')
{
$re = 'Online Contact Form';
$msg = 'FROM: '.$_POST['name'].$_POST['msg'];
$headers = 'From: $_POST[email] \r\n';
$myemail = $contact_emails[$_POST['contact']];
if (mail($myemail,$re,$msg, $headers))
{
echo 'Message sent, Thank you!';
} else {
echo 'There was an error sending your mail';
};
}
}
?>
That's what I currently have, all that needs to happen is all that info needs to be e-mailed to 1 address (currently in the action= attribute of the form)PHP Code:
<form action="mailto:recruit@lanrevolutionary.net" method="post" name="recruit" id="recruit">
<table width="500" borders="0" style="text-align: left;">
<tr>
<td><b>Real Name:</b></td>
<td><input type="text" name="name" id="name" size="20" maxlength="30" /></td>
</tr>
<tr>
<td><b>Player Name:</b></td>
<td><input type="text" name="player" id="player" size="20" maxlength="30" /></td>
</tr>
<tr>
<td><b>Gender:</b><br /></td>
<td><input type="radio" name="male" id="male" value="male" checked="checked" />Male<br />
<input type="radio" name="female" id="female" value="female" />Female</td>
</tr>
<tr>
<td><b>E-mail Address:</b></td>
<td><input type="text" name="email" id="email" size="30" maxlength="30" /></td>
</tr>
<tr>
<td><b>Verify E-mail:</b></td>
<td><input type="text" name="vemail" id="vemail" size="30" maxlength="30" /></td>
</tr>
<tr>
<td><b>MSN Messenger Address:</b></td>
<td><input type="text" name="vemail" id="vemail" size="30" maxlength="30" /></td>
</tr>
<tr>
<td><b>Recruiting Status</b></td>
<td><input type="radio" name="try" id="try" value="try" checked="checked" />Trying Out<br />
<input type="radio" name="rec" id="rec" value="recruited" />Previously Recruited</td>
</tr>
<tr>
<td>Please enter the name of who recruited you (If applicable)</td>
<td><select name="recruiter" id="recruiter">
<option>R1zeeK</option>
<option>Ghost</option>
<option>Sgt. Fynmore</option>
<option>Spiers</option>
<option>Phoenix</option>
<option>Other</option>
</select></td>
</tr>
<tr>
<td><b>Name of other (If applicable):</b></td>
<td><input type="text" name="vemail" id="vemail" size="30" maxlength="30" /></td>
</tr>
</table><br />
<input type="submit" value="Recruit" />
<input type="reset" value="Reset Form" />
</form>
Everything else needs to be laid out just like:
Name:
E-mail:
etc..
Something like that, find it quite tricky to understand all that PHP (but I roughly get it)
There are currently 1 users browsing this thread. (0 members and 1 guests)