I'm trying to build a form for wordpress. I've used plugins in the past but I need maximum control for some specific styling. I'm not very good with PHP yet, so am struggling trying to add checkboxes to the script.. I've removed my attempts and left the checkboxes in the html, but not in the PHP - can someone advise me of the best way to make any selected checkboxes visible in the email that is sent? Everything else works at the moment.
the html:
<form method="post" action="<?php bloginfo('template_directory'); ?>/contact.php">
<h3>Your Details</h3>
<div class="formrow">
<input type="text" name="Name" maxlength="99" id="fullname" placeholder="Name" />
<input type="email" name="Email" maxlength="99"placeholder="Email Address" />
<input type="tel" name="Phone" maxlength="25" placeholder="Phone Number" />
</div>
<h3>Project Type</h3>
<div class="formrow">
<fieldset>
<input type="checkbox" name="project1" value="Web">
<label for="type1">Web</label>
<input type="checkbox" name="project2" value="Digital">
<label for="type2">Digital</label>
<input type="checkbox" name="project3" value="Consultancy">
<label for="type3">Consultancy</label>
</fieldset>
</div>
<table align=center>
<tr><td colspan=2><strong>Contact us using this form:</strong></td></tr>
<tr><td>Department:</td><td><select name="sendto"> <option value="general#mycompany.com">General</option> <option value="support#mycompany.com">Support</option> <option value="sales#mycompany.com">Sales</option> </select></td></tr>
<tr><td>Company:</td><td><input size=25 name="Company"></td></tr>
<tr><td>Subscribe to<br> mailing list:</td><td><input type="radio" name="list" value="No"> No Thanks<br> <input type="radio" name="list" value="Yes" checked> Yes, keep me informed<br></td></tr>
<tr><td colspan=2>Message:</td></tr>
<tr><td colspan=2 align=center><textarea name="Message" rows=5 cols=35></textarea></td></tr>
<tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr>
<tr><td colspan=2 align=center><small>A <font color=red>*</font> indicates a field is required</small></td></tr>
</table>
</form>
the PHP:
<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";
$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Mailing List";
$fields{"Message"} = "Message";
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: noreply#YourCompany.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{print "Success";}
else
{print "We encountered an error sending your mail, please notify webmaster#YourCompany.com"; }
}
}
?>
Thanks! MC
An array of checkboxes would be most appropriate. By using [] in the checkbox names, PHP will automatically parse them into a native array.
<input type="checkbox" name="projects[]" value="Web">
<label for="type1">Web</label>
<input type="checkbox" name="projects[]" value="Digital">
<label for="type2">Digital</label>
<input type="checkbox" name="projects[]" value="Consultancy">
<label for="type3">Consultancy</label>
On the PHP side:
$selectedProjects = 'None';
if(isset($_POST['projects']) && is_array($_POST['projects']) && count($_POST['projects']) > 0){
$selectedProjects = implode(', ', $_POST['projects']);
}
$body .= 'Selected Projects: ' . $selectedProjects;
Outputs (if all checked)
Selected Projects: Web, Digital, Consultancy
Related
I am trying to send emails to only the users which i am selecting using checkbox from same index.php page. i am trying something here but i don't know that how to transfer and hold checked emails to "Bcc" field. here, is my code please have a look !
Php code for email (index.php) :
<?php
if (isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
$to = "";
$headers = "From:$name<$email>";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Bcc: $selectedemailsall\r\n";
$message = "Name: $name\n\n Email: $email \n\n Subject : $subject \n\n Message : $comments";
if(mail($to,$subject,$message,$headers))
{
echo "Email Send";
}
else
{
echo "Error : Please Try Again !";
}
}
?>
Code for form (index.php) :
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mail Document</title>
</head>
<body>
<form action="" method="post" >
<p>Name :<br>
<input type="text" name="name" id=""></p>
<p>Email :<br>
<input type="text" name="email" id=""></p>
<p>Subject :<br>
<input type="text" name="subject" id=""></p>
<p>Comments :<br>
<textarea name="comments" id="" cols="30" rows="10"></textarea></p>
<p><input type="submit" value="Send Email" name="SubmitEmail"></p>
</form>
<form action="#" method="post">
<?php
error_reporting(E_ERROR | E_PARSE);
$connection = mysqli_connect("localhost","root", "");
$db = mysqli_select_db("testdb", $connection);
$query = mysqli_query("select * from users", $connection);
while ($row = mysqli_fetch_array($query))
{
echo "
<input type='checkbox' name='check_list[]' value='{$row['email']}'>
<label>{$row['username']}</label><br/>
";
}
?>
<?php
if(isset($_POST['submituserchk']))
{
//to run PHP script on submit
if(!empty($_POST['check_list']))
{
// Loop to store and display values of individual checked checkbox.
foreach($_POST['check_list'] as $selectedemails)
{
$selectedemailsall = $selectedemails.",";
//echo $selectedemailsall;
}
}
}
?>
</div> <!-- End of RightUsersDivWithCheckBox -->
<input type="submit" name="submituserchk" style="margin-left: 87%; margin-top: 20px;" value="Done"/>
</form>
</body>
</html>
Any solution please how to do this ? right now when i click "Done" and submit emails nothing happens and i don't want to click "Done" button after selecting emails. I just select emails and they goes to "Bcc" field in a variable.
Don't use Bcc header for many users. Yo can make is:
Your form:
...
<input type="checkbox" name="email[]" value="foo#host.tld"> - foo#host.tld
<input type="checkbox" name="email[]" value="bar#host.tld"> - bar#host.tld
<input type="checkbox" name="email[]" value="baz#host.tld"> - baz#host.tld
...
Your backend code:
...
if (array_key_exists('email', $_POST) && is_array($_POST['email'])) {
foreach ($_POST['email'] as $to) {
mail($to, $subject, $message, $headers);
}
}
...
All emails sent separatelly for all recipients. This is flexible case for your application -- you can check for each send status.
Finally i got an answer to my own question. below is my code,
Display username, emails with checkbox from database :
$getemail = mysqli_query("SELECT * FROM users",$connection);
if(!$getemail) die('MsSQL Error: ' . mysqli_error());
echo '<div class="AllUserDiv" style="overflow-y:scroll;height:400px;"><table class="table table-bordered">';
echo "<thead>
<tr>
<th><input type='checkbox' onchange='checkedbox(this)' name='chk' /> </th>
<th>Username</th>
<th>Email</th>
</tr>
</thead>";
if(mysqli_num_rows($getemail) == 0)
{
echo "<tbody><tr><td colspan='3'> No Data Available</td></tr></tbody>";
}
while($row = mysqli_fetch_assoc($getemail))
{
echo "<tbody><tr><td><input value='".$row['email']."' type='checkbox' name='check[]' checked /> </td>";
echo "<td>".$row['username']."</td>";
echo "<td>".$row['email']."</td></tr></tbody>";
}
Email Form :
<form method="post" action="">
<p style="margin-top:30px;">Email Subject: <input type="text" name="subject" value="" class="form-control" /></p>
<p>Email Content: <textarea name="message" cols="40" rows="6" style="width:100%;"></textarea></p>
<center><input type="submit" name="submit" value="Send Email Now" class="btn btn-primary btn-block" />
</form>
JavaScript for making checkbox selection :
<script type="text/javascript" language="javascript">
function checkedbox(element)
{
var checkboxes = document.getElementById('input');
if(element.checked)
{
for (var i = 0; i < checkboxes.length; i++ )
{
if(checkboxes[i].type == 'checkbox')
{
checkboxes[i].checked = true;
}
}
}
else
{
for (var i = 0; i < checkboxes.length; i++)
{
console.log(i)
if(checkboxes[i].type == 'checkbox')
{
checkboxes[i].checked = false;
}
}
}
}
</script>
I am developing a site that uses javascript to handle many functions and PHP based Captcha code to validate the form field.
It works great, but the form will submit if none of the fields are filled in.
I need one of two form fields ['email' or 'phone'] filled in, but neither can be left blank.
The error message can be the same error message thrown up when the captcha field is left blank or filled in incorrectly.
I am new to PHP code and cannot figure out for the life of me how to call the function.
The function code is:
<?php
if(isset($_POST['send'])){
$emailFrom = "clientemail.com";
$emailTo = "clientemail.com";
$subject = "Contact Form Submission";
$first_name = strip_tags($_POST['first_name']);
$last_name = strip_tags($_POST['last_name']);
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
$message = strip_tags(stripslashes($_POST['message']));
$body .= "First Name: ".$first_name."\n";
$body .= "Last Name: ".$last_name."\n";
$body .= "Email: ".$email."\n";
$body .= "Phone: ".$phone."\n";
$body .= "Comments: ".$message."\n";
$headers = "From: ".$emailFrom."\n";
$headers .= "Reply-To:".$email."\n";
if($_SESSION['security_code'] == $_POST['security_code']){
$success = mail($emailTo, $subject, $body, $headers);
if ($success){
echo '<p class="yay">Your e–mail has been sent.</p>';
}
} else {
echo '<p class="oops">Something went wrong. Hit the back button and try again.</p>';
}
} else {
?>
The form field:
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post" id="contact" name="contact">
<fieldset>
<label for="name"><span style="color:#bf252b;">*</span>First Name</label>
<input type="text" id="first_name" name="first_name" minlength="2"/>
<label for="name">Last Name</label>
<input type="text" id="last_name" name="last_name" minlength="2"/>
<label for="email"><span style="color:#bf252b;">*</span> Email</label>
<input type="text" id="email" name="email" />
<label for="phone"><span style="color:#bf252b;">*</span> Phone</label>
<input type="text" id="phone" name="phone" />
<label for="message">Message</label><div style="clear:both;"></div>
<textarea id="message" name="message" cols="40" rows="10" ></textarea>
<img src="../captcha.php" id="captcha" alt="captcha" style="padding:25px 0px 20px 0px;" />
<label for="security_code">Enter captcha</label>
<input type="text" id="security_code" name="security_code" autocomplete="off" class="required"/>
<button type="submit" id="send" name="send" style="margin:0px 0px 10px 12px;">Send!</button>
</fieldset>
</form>
<?php } ?>
There is a .php document for running captcha, but am I right in thinking there is a simple solution for this; some extra code in the existing code that will fix my issue? I really want to avoid javascript and plugins if I can help it.
Thanks in advance!!
Try this,
if($_SESSION['security_code'] == $_POST['security_code'] && (!empty($email) || !empty($phone))) {
instead of
if ($_SESSION['security_code'] == $_POST['security_code']) {
This is not convenient way to validate form but I hope this will help.
Add the required attribute to the fields you need required.
Fix your code!
Notice: Undefined variable: body in /../sendform.php on line 14
Do that:
$body = "First Name: ".$first_name."\n";
$body .= "Last Name: ".$last_name."\n";
$body .= "Email: ".$email."\n";
$body .= "Phone: ".$phone."\n";
$body .= "Comments: ".$message."\n";
Solution
if(($_SESSION['security_code'] == $_POST['security_code']) AND
(!empty($email) OR !empty($phone)) ) {
In other words:
Security code must be match
Email or Phone can not be empty
Attempting to submit an HTML5 form to email via PHP, with a redirect to a "Thank you!" page after a successful submission. Problem is, the form isn't sending and the redirect isn't happening.
Here's my HTML:
<form id="vendorInfo" action="process_form_vendor.php" method="post">
<label for="vendorName">Vendor Name:</label>
<br />
<input id="vendorName" name="vendorName" type="text" maxlength="30" required>
<br />
<label for="contactName">Contact Name:</label> <br />
<input id="contactName" name="contactName" type="text" maxlength="35" required>
<br />
<label for="vendorType">Organization Type:</label>
<br />
<select id="vendorType" name="vendorType">
<option value="carrier">
Insurance Carrier
</option>
<option value="tech_crm">
Technology/CRM Management
</option>
<option value="leadProvider">
Lead Provider
</option>
<option value="info_comm">
Information/Communication
</option>
<option value="other">
Other (please describe below)
</option>
</select>
<br />
<label for="other1">Other Organization Type:</label>
<br />
<input id="other1" name="other1" type="text" maxlength="25">
<br />
<label for="email">Email:</label>
<br />
<input id="email" name="email" type="email" maxlength="30" required>
<br />
<label for="phone">Phone:</label>
<br />
<input id="phone" name="phone" type="tel" maxlength="12" required placeholder="xxx-xxx-xxxx">
<br />
<label for="questions">Any questions or comments? Leave them here:</label>
<br />
<textarea id="questions" name="questions" rows="10" maxlength="300"></textarea>
<br />
<br />
<fieldset id="selectionBox">
<legend id="packageSelect">
The following sponsorship packages are available for the Sales Summit; contact <ahref="mailto:email#domain.com”>Amanda</a> for pricing and details:
</legend>
<input type="radio" name="packageSelect" value="Bronze Package" checked> Bronze
<br />
<br />
<input type="radio" name="packageSelect" value="Silver Package"> Silver
<br />
<br />
<input type="radio" name="packageSelect" value="Gold Lunch Package"> Gold (breakfast; exclusive sponsorship)
<br />
<br />
<input type="radio" name="packageSelect" value="Gold Breakfast Package"> Gold (lunch; exclusive sponsorship)
<br />
<br />
<input type="radio" name="packageSelect" value="Gold Trade Show Package"> Gold (trade show; exclusive sponsorship)
</fieldset>
<br />
<button type="submit" name="submit">Submit</button> <button type="reset" name="reset">Reset</button>
<br />
</form>
And here is my PHP:
<?php
if(!isset($_POST['submit']))
{
echo "error; you need to submit the form!";
}
$vendorName = $_POST['vendorName'];
$contactName = $_POST['contactName'];
$vendorType = $_POST['vendorType'];
$other1 = $_POST['other1'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$questions = $_POST['questions'];
$packageSelect = $_POST['packageSelect'];
if (empty($vendorName)||(empty($contactName)||(empty($vendorType)||(empty($email)||(empty($phone)||(empty($packageSelect)) {
echo "Vendor Name, Contact Name, Vendor Type, Email, Phone, and Package Selection are mandatory!";
exit;
}
$email_from = 'email#domain.net';
$email_subject = '2014 SMS Sales Summit - New Vendor Reservation Request';
$email_body = "You have received a new vendor reservation request for the 2014 SMS Sales Summit from $contactName at $vendorName.\n".
"Vendor Type: $vendorType\n".
"Other Vendor Type: $other1\n".
"Email Address: $email\n".
"Phone Number: $phone\n".
"Additional Questions: $questions\n".
"Sponsorship Level: $packageSelect\n".
$to = 'email#domain.net';
$headers = "$email_from \r\n";
$headers .= "Reply-To: $email \r\n";
mail($to,$email_subject,$email_body,$headers);
header('Location: thank-you.html');
?>
I have no idea what's going on or why this isn't working. Any ideas?
(Tested) Give this a try, it worked for me.
Plus, you may get an error saying "headers already sent", which did for me, so I used an echo at the end and I commented your header(".... to test with. If you have a space before <?php this could cause the error message to appear. You can try using ob_start(); just below your opening PHP tag.
Your empty conditionals ) had some too many, and some missing/not at the right spot.
Plus, a missing closing semi-colon at the end of "Sponsorship Level: $packageSelect\n". where there was a dot. Plus a missing From: which has been added.
<?php
// uncomment line below to use with header redirect
// ob_start();
if(!isset($_POST['submit']))
{
echo "error you need to submit the form!";
}
$vendorName = $_POST['vendorName'];
$contactName = $_POST['contactName'];
$vendorType = $_POST['vendorType'];
$other1 = $_POST['other1'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$questions = $_POST['questions'];
$packageSelect = $_POST['packageSelect'];
if (empty($vendorName)|| empty($contactName)|| empty($vendorType)|| empty($email)|| empty($phone)|| empty($packageSelect)){
echo "Vendor Name, Contact Name, Vendor Type, Email, Phone, and Package Selection are mandatory!";
exit;
}
$email_from = 'email#domain.net';
$email_subject = '2014 SMS Sales Summit - New Vendor Reservation Request';
$email_body = "You have received a new vendor reservation request for the 2014 SMS Sales Summit from $contactName at $vendorName.\n".
"Vendor Type: $vendorType\n".
"Other Vendor Type: $other1\n".
"Email Address: $email\n".
"Phone Number: $phone\n".
"Additional Questions: $questions\n".
"Sponsorship Level: $packageSelect\n";
$to = "email#domain.net";
$headers = 'From: ' . $email_from . "\r\n";
$headers .= "Reply-To: $email \r\n";
mail($to,$email_subject,$email_body,$headers);
// header('Location: thank-you.html');
echo "thanks";
?>
Footnotes:
If it still does not "send", then change:
<button type="submit" name="submit">Submit</button>
to:
<input type="submit" name="submit" value="Submit">
If you use the header("... along with the ob_start(); you must not use the echo below it. Just comment that out.
You have syntax error in $email_from and $to. Need to use '(single quotes) or " (double quotes) instead of ‘ . Try this,
$email_from = 'email#domain.net';
...^ ^....
instead of
$email_from = ‘email#domain.net’;
Also, in your if condition you have missed to add lots of )
if (empty($vendorName)||
empty($contactName)||
empty($vendorType)||
empty($email)||
empty($phone)||
empty($packageSelect) ) {
echo "Vendor Name, Contact Name, Vendor Type, Email, Phone, and Package Selection are mandatory!";
exit;
}
<button type="submit&" name="submit">Submit</button> <button type="reset" name="reset">Reset</button>
to
<button type="submit" name="submit">Submit</button> <button type="reset" name="reset">Reset</button>
Is the form submitting from frontend?
also in php code, the $email_from:
$email_from = ‘email#domain.net’;
change it to:
$email_from = 'email#domain.net';
note the difference in single quotes. Same goes for $to:
$to = ‘email#domain.net';
change it to:
$to = 'email#domain.net';
Can you remove the "&" in <button type ="submit&">?
You also need to close the form using </form> after the last line
Why the & in type="submit&"? Also, there is no closing </form> tag.
you forgot to put a semicolon after $email_body
please put one
$email_body = "";
I am trying to create three forms. The way it should work is a form should appear and the user is able to input their info. When the submit button is pressed an email should be sent to the supervisor and the supervisor should click on a link and another form should appear. When the supervisor fills the form and then clicks submit an email should be submitted to the client. the client will click on the link and fill the form out. The client should be then able to send an email to the employee and the both the supervisor and the original user should be able to get the response. However when I keep creating the form the php keeps breaking after the second form. I cant seem to figure out why it keeps breaking in the third form.
here is a snippit of the php code for the second form:
if ($_POST['token'] == "2") {
$m = new mysql($connection_information);
$m->update('hello',array('approval'=>$_POST['approval'],
'comment'=>$_POST['comment'],
'approved_by'=>$_POST['approval_by'],
'approved_date'=>time()),'uid=\''.$_POST['uid'].'\'');
$records = $m->row(array('table' => 'hello','condition' => 'uid=\''.$_POST['uid'].'\''));
$eemail = records['email'];
$supemail = $records['supervemail'];
$clemail = $records['cemail'];
$approvaltime = date("m/d/y g:i a",$records['approved_date']);
$subject = " " . $clemail;
$headers = 'From: ' . $supemail . "\r\n" .
'Reply-To: ' . $supemail . "\r\n" .
'MIME-Version: 1.0' . "\r\n";
if($records['approval'] == 1){
$travel_action = 'approved';
}else{
$travel_action = 'rejected';
}
$message = " Travel Estimation ".$travel_action." on ".$approvaltime." by ".$records['approved_by']. "\r\n" . "Comment: " .$records['comment']. "\r\n";
mail($eemail, $subject, $message, $headers);
Here is my html portion:
<?php if ($_POST['token'] == "2") { ?>
<h1>Approval Decision Submited.</h1>
<?php } else if ($_POST['token'] == "1") {
echo "<h1>Form has been submitted</h1>";
} else {
if (isset($_GET['uid']) && isset($records)){
?>
<form id="approvalForm" name="form2" action="hello.php" method="POST">
<input type="hidden" name="token" value="2">
<input type="hidden" name="uid" value="<?php echo $_GET['uid'] ?>">
<fieldset>
<legend>Manager Approval Required</legend>
Submitted on: <?php echo date("m/d/y g:i a",$records['submitted']) ?><br/>
By: <?php echo $records['email'] ?><br/>
<label for="email">Supervisor's Email: </label>
<input type="text" name="email" title="Email" value="<?php echo $records['supervemail'] ?>"><br>
<label for="email">Client's Email: </label>
<input type="text" name="email" title="Email" value="<?php echo $records['supervemail'] ?>"><br>
<label for="email">Employee's Email: </label>
<input type="text" name="email" title="Email" value="<?php echo $records['supervemail'] ?>"><br>
<label for="approval_by">Please Enter your name for approval: </label>
<input type="text" name="approval_by" id="approval_by" title="Approved By" ><br>
<label for="approval">Please select appropriate action: </label>
<select name="approval" id="approval">
<option value="">Please Select Action</option>
<option value="1">Approval</option>
<option value="0">Rejection</option>
</select>
<label for="comment" >Comment: </label>
<input type="text" name="comment" id="comment" title="comment"><br>
<input class="submit" type="submit" value="Submit"/>
</fieldset>
</form>
In my third form I want the supervisor to send an email to the client so the that the client will receive the link and approve or disapprove in the third form. From there they can submit an email to the user if they agree or disagree. I made it so the third form looks almost identical to the second form. Is that where my fault lies?
I notice that the records array for the eemail variable does not have a dollar sign.
$eemail = records['email'];
Should be
$eemail = $records['email'];
This is a followup to a question I posted yesterday. I thought everything was working fine, but today, I am not getting any results in the email from the drop down field.
Here is the form code in question:
<form method="post" action="contact.php" name="contactform" id="contactform">
<fieldset>
<legend>Please fill in the following form to contact us</legend>
<label for="name"><span class="required">*</span> Your Name</label>
<input name="name" type="text" id="name" size="30" value="" />
<br />
<label for="company">Company</label>
<input name="company" type="text" id="company" size="30" value="" />
<br />
<label for="email"><span class="required">*</span> Email</label>
<input name="email" type="text" id="email" size="30" value="" />
<br />
<label for="phone"><span class="required">*</span> Phone</label>
<input name="phone" type="text" id="phone" size="30" value="" />
<br />
<label for="purpose"><span class="required">*</span> Purpose</label>
<select name="purpose" id="purpose" style="width: 300px; height:35px;">
<option value="none selected" selected="selected">-- Select One --</option>
<option value="I am interested in your services">I am interested in your services!</option>
<option value="I am interested in a partnership">I am interested in a partnership!</option>
<option value="I am interested in a job">I am interested in a job!</option>
</select>
<br />
<label for=comments><span class="required">*</span> Comments</label>
<textarea name="comments" cols="40" rows="3" id="comments" style="width: 350px;"></textarea>
<p><span class="required">*</span> Please help us control spam.</p>
<label for=verify accesskey=V> 3 + 1 =</label>
<input name="verify" type="text" id="verify" size="4" value="" style="width: 30px;" /><br /><br />
<input type="submit" class="submit" id="submit" value="Submit" />
</fieldset>
</form>
It is then processed in PHP and should output the selected option to an email, however the Reason for Contact line always comes through with nothing in it.
Here is the PHP code:
<?php
if(!$_POST) exit;
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$purpose = $_POST['purpose'];
$comments = $_POST['comments'];
$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div class="error_message">Attention! Please enter a valid phone number.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Attention! Please enter your message.</div>';
exit();
} else if(trim($verify) == '') {
echo '<div class="error_message">Attention! Please enter the verification number.</div>';
exit();
} else if(trim($verify) != '4') {
echo '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
exit();
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
$address = "myname#email.com";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'You\'ve been contacted by ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name.\r\n\n";
$e_company = "Company: $company\r\n\n";
$e_content = "Comments: \"$comments\"\r\n\n";
$e_purpose = "Reason for contact: $purpose\r\n\n";
$e_reply = "You can contact $name via email, $email or via phone $phone";
$msg = $e_body . $e_content . $e_company . $e_purpose . $e_reply;
if(mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n")) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
}
function isEmail($email) { // Email address verification, do not edit.
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
?>
Any assistance would be greatly appreciated. Thanks!
It really looks like it should work, so I'd verify the dumbly obvious stuff: is your <select> tag contained within the <form> tag? Is 'purpose' mis-typed somewhere (it all looks good here, from what I can see)?
What happens if you do print_r($_POST)?
What happens if you do var_dump($purpose) after it is initialized?
Did you check if the server is able to send emails?
Check if sendmail actually works on your server before trying to debug your code (that seems to be good).