Here is my Code. But I feel that my code isn't really that much object oriented.
There is a small piece of "styling" in it as well, the "message error" thing at the end.
Should that be in my class or should it go somewhere else?
<?php
require 'contact.class.php';
?>
<form action="" method="post">
<?php
if (isset($_POST["submit"])) {
$sendMail = new gw2Mail();
$sendMail->senderName = $_POST['senderName'];
$sendMail->senderEmail = $_POST['senderEmail'];
$sendMail->recipient = $_POST['recipient'];
$sendMail->copy = $_POST['copy'];
$sendMail->subject = $_POST['subject'];
$sendMail->message = $_POST['message'];
$sendMail->sendMail();
}
?>
<table class='ipb_table ipsMemberList'>
<tr class='header' colspan='4'>
<th scope='col' colspan='5'>Send E-mail</th>
</tr>
<tr class='row1'>
<td style='width: 50%'><strong>From:</strong><br />Enter the sender's name in this field.</td>
<td><input type="text" class="input_text" name="senderName" id="senderName" value="<?php if (isset($_POST['senderName'])) { echo $_POST['senderName']; } ?>" size="50" maxlength="125" /></td>
</tr>
<tr class='row2'>
<td style='width: 50%'><strong>From E-mail:</strong><br />Enter the sender's e-mail address in this field.</td>
<td><input type="text" class="input_text" name="senderEmail" id="senderEmail" value="<?php if (isset($_POST['senderEmail'])) { echo $_POST['senderEmail']; } ?>" size="50" maxlength="125" /></td>
</tr>
<tr class='row1'>
<td style='width: 50%'><strong>Recipient:</strong><br />Enter the recipient's e-mail address in this field.</td>
<td><input type="text" class="input_text" name="recipient" id="recipient" value="<?php if (isset($_POST['recipient'])) { echo $_POST['recipient']; } ?>" size="50" maxlength="125" /></td>
</tr>
<tr class='row2'>
<td style='width: 50%'><strong>Carbon Copy:</strong><br />Send a copy to someone else? Enter another e-mail address here. Leave blank for no copy.</td>
<td><input type="text" class="input_text" name="copy" id="copy" value="<?php if (isset($_POST['copy'])) { echo $_POST['copy']; } ?>" size="50" maxlength="125" /></td>
</tr>
<tr class='row1'>
<td style='width: 50%'><strong>Subject:</strong><br />Enter a subject in this field.</td>
<td><input type="text" class="input_text" name="subject" id="subject" value="<?php if (isset($_POST['subject'])) { echo $_POST['subject']; } ?>" size="50" maxlength="50" /></td>
</tr>
<tr class='row2'>
<td colspan='2' style='width: 100%'><textarea style="height: 250px; width: 99%;" name="message" id="message" cols="30" rows="14" virtual wrap="on"><?php if (isset($_POST['message'])) { echo $_POST['message']; } ?></textarea></td>
</tr>
</table>
<input type="submit" name="submit" value="Submit" tabindex="50" class="input_submit" accesskey="s" />
</form>
And this is the contact.class.php:
<?php
class gw2Mail {
var $senderName;
var $senderEmail;
var $recipient;
var $copy;
var $subject;
var $message;
var $bcc;
public function sendMail()
{
if ($this->senderName != "") {
$this->senderName = filter_var($this->senderName, FILTER_SANITIZE_STRING);
if ($this->senderName == "") {
$errors .= '- Please enter a valid name!';
}
} else {
$errors .= '- You forgot to enter a name!<br />';
}
if ($this->senderEmail != "") {
$this->senderEmail = filter_var($this->senderEmail, FILTER_SANITIZE_STRING);
if ($this->senderEmail == "") {
$errors .= '- Please enter a valid Email!';
}
} else {
$errors .= '- You forgot to enter an email!<br />';
}
if ($this->recipient != "") {
$this->recipient = filter_var($this->recipient, FILTER_SANITIZE_STRING);
if ($this->recipient == "") {
$errors .= '- Please enter a valid recipient email!';
}
} else {
$errors .= '- You forgot to enter a recipient email!<br />';
}
if ($this->subject != "") {
$this->subject = filter_var($this->subject, FILTER_SANITIZE_STRING);
if ($this->subject == "") {
$errors .= '- Please enter a valid subject!';
}
} else {
$errors .= '- You forgot to enter a subject!<br />';
}
if ($this->message != "") {
$this->message = filter_var($this->message, FILTER_SANITIZE_STRING);
if ($this->message == "") {
$errors .= '- Please enter a valid message!';
}
} else {
$errors .= '- You forgot to enter a message!<br />';
}
if (!$errors) {
$this->bcc="";
$headers = "From: $this->senderName <$this->senderEmail>";
$headers .= "\r\nCc: $this->copy";
$headers .= "\r\nBcc: $this->bcc\r\n\r\n";
$send_contact=mail("$this->recipient","$this->subject","$this->message","$headers");
} else {
echo '<p class=\'message error\'>';
echo '<font color="#FFFFFF">' . $errors . '</font>';
echo '</p><br />';
}
}
}
?>