I am receiving blank emails from my website every day at 8:15am - 8:19am.
They don't contain any information in them and do not contain the input id's either.
I have gone through multiple forums about this but I am new to PHP and seams to be a bit over my head.
<?php
function sendFormByEMail($msgBody) {
$to = "email#gmail.com";
$subject = "web visitor";
$from = "email#gmail.com";
$mailHdr = "";
$mailHdr .= "From: ".$from."\r\n";
$mailHdr .= "Reply-To: ".$from."\r\n";
return mail($to, $subject, $msgBody, $mailHdr);
}
function getMessageText() {
$msgTxt = "";
$msgTxt .= "Sent: " . date("Y/m/d H:i:s") . "\n";
foreach ($_POST as $key => $value)
{
//$msgTxt .= urlencode($key) . "=" . urlencode($value) . "\n";
$msgTxt .= $key . " = " . $value . "\n";
}
return $msgTxt;
}
if (sendFormByEMail(getMessageText())) {
$nextPage = '../index2.html';
} else {
$nextPage = '../index2.html';
}
header("Location: $nextPage");
?>
HTML
<form action="php/formsProcessor.php" method="post" enctype="multipart/form-data" name="quote" id="quote">
<div class="row">
<label for="name">Your name:</label><br />
<input id="name" class="input" name="name" type="text" value="" size="30" /><br />
</div>
<div class="row">
<label for="email">Your email:</label><br />
<input id="email" class="input" name="email" type="text" value="" size="30" /><br />
</div>
<div class="row">
<label for="message">Your message:</label><br />
<textarea id="message" class="input" name="message" rows="7" cols="30"></textarea><br />
</div>
<input id="submit_button" type="submit" value="Send email" />
</form>
I have been trying to fix this for a few weeks now and any help would be GREATLY appreciated.
Add this text to the header:
"Content-type: text/html charset=iso-8859-1 \r\n"
Related
The Contact page which has form submission, https://photos.app.goo.gl/GpbWvks2Y3SjwmX58 is not being executed. I tried various solutions from other questions that's already been asked but had no luck.
The .php file is in the Contacts folder along with the Contacts/index.html page.
Some expert help would be much appreciated.
Here's the Javascript on the HTML page.
<script type="text/javascript">document.getElementById('spc').value = '755fd9ccedf916b2cd08bb7be88691dd';</script>
<form name="enquiry" method="post" action="infosemantic-enquiryform1.php" class="form" id="form">
<p class="input_field">
<label class="field">First Name:</label>
<input name="name" type="text" class="name_box" id="name" value="" size="35">
</p>
<p class="input_field">
<label class="field">Last Name:</label>
<input name="lastname" type="text" class="name_box" id="lastname" value="" size="35">
</p>
<p class="input_field">
<label class="field">Title:</label>
<input name="title" type="text" class="name_box" id="title" value="" size="35">
</p>
<p class="input_field">
<label class="field">Company:</label>
<input value="" name="company" class="name_box" size="35" type="text">
</p>
<p class="input_field">
<label class="field">E-mail Address:</label>
<input name="email" type="text" class="name_box" id="email" value="" size="35">
</p>
<p class="input_field">
<label class="field">Message:</label>
<textarea name="Message" id="csinbr" cols="45" rows="5" class="name_box2" w></textarea>
</p>
<p class="btn"><input name="Subject" value="Enquiry from DSR Power" type="hidden">
<input name="Submit" value="Submit " class="sbm" type="submit">
<input name="Reset" value="Clear Form" class="sbm" type="reset">
</p>
<font face="Verdana" size="2">
<font face="Verdana" size="2">
<input name="form_name" value="rajforever2" type="hidden">
</font>
<input name="userid" value="webindia" type="hidden">
</font>
</form>
</div>
$message = "<html><body><table align='center' boarder='1' cellpadding='5' cellspacing='2' style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;font-weight:bold;background-color:#CCCCFF;color:#000000;;border:double'>";
$message .= "<tr><td align='left'><b> Name </b></td><td>:</td><td>".$_POST['name']."</td></tr>";
$message .= "<tr><td align='left'><b>Last Name </b></td><td>:</td><td>".$_POST['lastname']."</td></tr>";
$message .= "<tr><td align='left'><b>Title </b></td><td>:</td><td>".$_POST['title']."</td></tr>";
$message .= "<tr><td align='left'><b>Company </b></td><td>:</td><td>".$_POST['company']."</td></tr>";
$message .= "<tr><td align='left'><b>Email </b></td><td>:</td><td>".$_POST['email']."</td></tr>";
$message .= "<tr><td align='left'><b>Message</b></td><td>:</td><td>".$_POST['Message']."</td></tr>";
$message .= "</table></body></html>";
/*to avoid spam mails in contact form*/
// Select if you want to check form for standard spam text
$SpamCheck = "Y"; // Y or N
$SpamReplaceText = "*content removed*";
// Error message prited if spam form attack found
$SpamErrorMessage = "<p align=\"center\"><font color=\"red\">Malicious code content detected.</font><br><b>Your IP Number of <b>".
getenv("REMOTE_ADDR").
"</b> has been logged.</b></p>";
$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['comments'];
if ($SpamCheck == "Y") {
// Check for Website URL's in the form input boxes as if we block website URLs from the form,
// then this will stop the spammers wastignt ime sending emails
if (preg_match("/http/i", "$name")) {
echo "$SpamErrorMessage";
exit();
}
if (preg_match("/http/i", "$email")) {
echo "$SpamErrorMessage";
exit();
}
if (preg_match("/http/i", "$msg")) {
echo "$SpamErrorMessage";
exit();
}
// Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer
$pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i'; // build the pattern match string
$name = preg_replace($pattern, "", $name);
$email = preg_replace($pattern, "", $email);
$msg = preg_replace($pattern, "", $msg);
// Check for the injected headers from the spammer attempt
// This will replace the injection attempt text with the string you have set in the above config section
$find = ["/bcc\:/i", "/Content\-Type\:/i", "/cc\:/i", "/to\:/i"];
$email = preg_replace($find, "$SpamReplaceText", $email);
$name = preg_replace($find, "$SpamReplaceText", $name);
$msg = preg_replace($find, "$SpamReplaceText", $msg);
// Check to see if the fields contain any content we want to ban
if (stristr($name, $SpamReplaceText) !== false) {
echo "$SpamErrorMessage";
exit();
}
if (stristr($msg, $SpamReplaceText) !== false) {
echo "$SpamErrorMessage";
exit();
}
// Do a check on the send email and subject text
if (stristr($to, $SpamReplaceText) !== false) {
echo "$SpamErrorMessage";
exit();
}
if (stristr($subject, $SpamReplaceText) !== false) {
echo "$SpamErrorMessage";
exit();
}
}
/*End*/
$headers = "From: $_POST[email]"."\r\n";
$headers .= 'Bcc:bharath#briofactors.com'."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1; format=flowed\n';
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "X-Mailer: PHP\n";
if (mail($to, $subject, $message, $headers)) {
header("location:thanks.html");
}
I was trying to send multiple vars from my html form to my email by using PHP. The problem is that I do not know anything about PHP. I found a simple form which worked for me, but it contained only 3 vars, subject, email and message. This time however I have 7.
Here's the code.
<?php
$projectname = htmlentities($_POST['projectname']);
$projectemail = trim(strip_tags($_POST['projectemail']));
$projectphone = htmlentities($_POST['projectphone']);
$projectcompany = htmlentities($_POST['projectcompany']);
$projecttype = trim(strip_tags($_POST['projecttype']));
$projecttimeline = htmlentities($_POST['projecttimeline']);
$aboutproject = htmlentities($_POST['aboutproject']);
$message = "{$projectname}{$projectphone}{$projectcompany}{$projecttimeline}{$aboutproject}";
$subject = $projecttype;
$to = 'myemail#gmail.com';
$body = <<<HTML
$message
HTML;
$headers = "From: $projectemail\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $body, $headers);
header('Location: thanks.html');
?>
And the corresponding HTML
<form id="formproject" action="thank_you_project.php" method="post">
<label for="name">Name</label>
<input type="text" id="projectname" name="name">
<label for="email">Email</label>
<input type="text" id="projectemail" name="email">
<label for="phone">Phone</label>
<input type="text" id="projectphone" name="phone">
<label for="company">Company</label>
<input type="text" id="projectcompany" name="company">
<label for="typeofproject">Type of project</label>
<input type="text" id="projecttype" name="typeofproject">
<label for="timeline">Timeline</label>
<input type="text" id="projecttimeline" name="timeline">
<label for="message">Message</label>
<textarea name="message" id="aboutproject" cols="30" rows="10"></textarea>
<input type="submit" id="projectsend" value="Send"></input>
</form>
</div> <!-- end form -->
Edited the PHP, left out the body and put message in mail instead, still not working.
<?php
$projectname = htmlentities($_POST['projectname']);
$projectemail = trim(strip_tags($_POST['projectemail']));
$projectphone = htmlentities($_POST['projectphone']);
$projectcompany = htmlentities($_POST['projectcompany']);
$projecttype = trim(strip_tags($_POST['projecttype']));
$projecttimeline = htmlentities($_POST['projecttimeline']);
$aboutproject = htmlentities($_POST['aboutproject']);
$message = "{$projectname}{$projectphone}{$projectcompany}{$projecttimeline}{$aboutproject}";
$subject = $projecttype;
$to = 'albermy145#alberttomasiak.be';
$headers = "From: $projectemail\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
header('Location: thanks.html');
?>
Try this,
<?php
$to = 'myemail#gmail.com';
$projectname = htmlentities($_POST['projectname']);
$projectemail = trim(strip_tags($_POST['projectemail']));
$projectphone = htmlentities($_POST['projectphone']);
$projectcompany = htmlentities($_POST['projectcompany']);
$projecttype = trim(strip_tags($_POST['projecttype']));
$projecttimeline = htmlentities($_POST['projecttimeline']);
$aboutproject = htmlentities($_POST['aboutproject']);
$header = "From: $projectemail \r\n";
$subject = $projecttype;
$message = "
<html>
<head>
<title></title>
</head>
<body>
<p>Your HTML</p>
Project Name : $projectname
<br/>
Project Email : $projectemail
<br/>
Project Phone : $projectphone
...
...
...
...
</body>
</html>
";
$message .= "";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if($retval == true)
{
header('Location: thanks.html');
exit();
}
?>
}
HTML
<form id="formproject" action="thank_you_project.php" method="post">
<label for="name">Name</label>
<input type="text" id="projectname" name="projectname">
<label for="email">Email</label>
<input type="text" id="projectemail" name="projectemail">
<label for="phone">Phone</label>
<input type="text" id="projectphone" name="projectphone">
<label for="company">Company</label>
<input type="text" id="projectcompany" name="projectcompany">
<label for="typeofproject">Type of project</label>
<input type="text" id="projecttype" name="projecttype">
<label for="timeline">Timeline</label>
<input type="text" id="projecttimeline" name="projecttimeline">
<label for="message">Message</label>
<textarea name="aboutproject" id="aboutproject" cols="30" rows="10"></textarea>
<input type="submit" id="projectsend" value="Send"></input>
</form>
</div> <!-- end form -->
Add all variables into $body (which is the third param of mail function).
//$body = <<<HTML
//$message <br>
//$projectname <br>
//$projectcompany<br>
//...
//HTML;
Or the second way is to add these vars into the third mail param directly.
mail($to, $subject, $message, $headers);
// this code is updated as I wrote in my comment below.
the form posted the value of input is using 'name' attribute as identifier of value,
<form id="formproject" action="thank_you_project.php" method="post">
<label for="name">Name</label>
<input type="text" id="projectname" name="name">
<label for="email">Email</label>
<input type="text" id="projectemail" name="email">
<label for="phone">Phone</label>
<input type="text" id="projectphone" name="phone">
<label for="company">Company</label>
<input type="text" id="projectcompany" name="company">
<label for="typeofproject">Type of project</label>
<input type="text" id="projecttype" name="typeofproject">
<label for="timeline">Timeline</label>
<input type="text" id="projecttimeline" name="timeline">
<label for="message">Message</label>
<textarea name="message" id="aboutproject" cols="30" rows="10"></textarea>
<input type="submit" id="projectsend" value="Send"></input>
</form>
<!-- end form -->
<?php
$projectname = htmlentities($_POST['name']);
$projectemail = trim(strip_tags($_POST['email']));
$projectphone = htmlentities($_POST['phone']);
$projectcompany = htmlentities($_POST['company']);
$projecttype = trim(strip_tags($_POST['typeofproject']));
$projecttimeline = htmlentities($_POST['timeline']);
$aboutproject = htmlentities($_POST['message']);
?>
I have created a contact form shortcode plugin for wordpress. However, the issue I am having is that I can't seem to echo the parameters of the shortcode in the php mailer file.
As an example my shortcode will look like this:
[vc-contact-form title="contact form" recipient_email="email#emailaddress.com]
The PHP code that generates this shortcode is here:
extract(shortcode_atts(array(
'el_class' => '',
'title' => '',
'subtitle' => '',
'recipient_email' => '',
), $atts));
$el_class = $this->getExtraClass($el_class);
$css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG,$el_class, $this->settings['base']);
$subtitle = '<legend>'.$subtitle.'</legend>';
$recipient_email = '<input type="hidden" name="recipient_email" id="recipient_email" value="'.$recipient_email.'" /><br />';
$output .= '<div class="contact-form '.$css_class.'" >';
$output .= '<h4 class="form-title">'.$title.'</h4>';
$output .= '<div id="contact">
<div id="message"></div>
<form method="post" action="'. VCPB_PLUGIN_URL . 'contact.php' .'" name="contactform" id="contactform">
<fieldset>';
$output .= $subtitle;
$output .= '<label for="name" accesskey="U"><span class="required">*</span> Your Name</label>
<input name="name" type="text" id="name" size="30" value="" />
<br />
<label for="email" accesskey="E"><span class="required">*</span> Email</label>
<input name="email" type="text" id="email" size="30" value="" />
<br />
<label for="phone" accesskey="P"><span class="required">*</span> Phone</label>
<input name="phone" type="text" id="phone" size="30" value="" />
<br />
<label for="comments" accesskey="C"><span class="required">*</span> Your message</label>
<textarea name="comments" cols="40" rows="5" id="comments" style="width: 350px;"></textarea>
<p><span class="required">*</span> Are you human?</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" />';
$output .= $recipient_email;
$output .= '</fieldset>
</form>
</div>';
$output .= '</div>'; /* END .contact-form */
return $output;
}
}
This shortcode will output the following html:
<div class="contact-form " >
<h4 class="form-title">Contact Form</h4>
<div id="contact">
<div id="message"></div>
<form method="post" action="http://www.skizzar.com/jsdrumming/wp-content/plugins/vc-contact-form/contact.php" name="contactform" id="contactform">
<fieldset><legend>Please fill in the form below to get in touch with me</legend><label for="name" accesskey="U"><span class="required">*</span> Your Name</label>
<input name="name" type="text" id="name" size="30" value="" />
<br />
<label for="email" accesskey="E"><span class="required">*</span> Email</label>
<input name="email" type="text" id="email" size="30" value="" />
<br />
<label for="phone" accesskey="P"><span class="required">*</span> Phone</label>
<input name="phone" type="text" id="phone" size="30" value="" />
<br />
<label for="comments" accesskey="C"><span class="required">*</span> Your message</label>
<textarea name="comments" cols="40" rows="5" id="comments" style="width: 350px;"></textarea>
<p><span class="required">*</span> Are you human?</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" /><input type="hidden" name="recipient_email" id="recipient_email" value="sam#skizzar.com" /><br /></fieldset>
</form>
</div>
</div>
From this you can see it uses a php mailer (contact.php). The code in this is as follows:
<?php
if(!$_POST) exit;
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$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(!is_numeric($phone)) {
echo '<div class="error_message">Attention! Phone number can only contain digits.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have entered 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(!isset($verify) || 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(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
$address = 'THIS NEEDS TO BE THE EMAIL ADDRESS FROM THE SHORTCODE';
$e_subject = 'You\'ve been contacted by ' . $name . '.';
$e_body = "You have been contacted by $name, their message is as follows." . PHP_EOL . PHP_EOL;
$e_content = "\"$comments\"" . PHP_EOL . PHP_EOL;
$e_reply = "You can contact $name via email, $email or via phone $phone";
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// 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!';
}
?>
What I am trying to do is grab the email address written in the shortcode (recipient_email) and place it in the contact.php script on this line:
$address = 'THIS NEEDS TO BE THE EMAIL ADDRESS FROM THE SHORTCODE';
I'm wondering if it's possible to combine the script that generates the shortcode html AND the php mailer, into one document as I can grab the email address easily within the shortcode script. Is this possible to do and what kind of modifications do I need to make to my script?
I'm new to WordPress. I create a static page contact.php. In contact page, I have a contact form, so users would get in touch with me. When the user would click the submit button it should go to index.php and prompting the success of email delivery otherwise display not successful..
this is the code of contact.php
<form class="form" method="post" action="/send-email.php">
<p class="name">
<input type="text" name="name" id="name" placeholder="Enter your name" size="40" />
<label for="name">Name</label>
</p>
<p class="email">
<input type="text" name="email" id="email" placeholder="mail#example.com" size="40" />
<label for="email">Email</label>
</p>
<p class="web">
<input type="text" name="telephone" id="telephone" placeholder="000-000-000" size="40" />
<label for="telephone">Telephone</label>
</p>
<p class="text">
<label for="message">Message</label>
<textarea name="message" placeholder="Write something to us" cols="40" rows="5" /></textarea>
</p>
<p class="submit">
<input type="submit" value="Send" />
<input type="reset" value="Cancel" />
</p>
</form>
send-email.php
<?php
$ToEmail = 'sample#sample.com';
$EmailSubject = 'Contact Form';
$mailheader = "From: " . $_POST["email"] . "\r\n";
$mailheader .= "Reply-To: " . $_POST["email"] . "\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = " <strong>Name:</strong> " . $_POST["name"] . "";
$MESSAGE_BODY .= "<br> <strong>Email:</strong> " . $_POST["email"] . "";
$MESSAGE_BODY .= "<br> <strong>Telephone:</strong> " . $_POST["telephone"] . "";
$MESSAGE_BODY .= "<br><br> <strong>Message:</strong> " . nl2br($_POST["message"]) . "";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die("Failure");
/* echo "<pre>";
print_r($MESSAGE_BODY);
echo "<pre>"; */
header("Location: /index");
But it's not sending. And the URL looks just like www.site.com/send-email.php
What am I missing in here? Any ideas? I would really appreciate your help. Thanks.
Sounds like die("Failure") might be kicking in and logging the "Failure" message instead of printing it on screen. Or the mail module isn't installed, so it is running into an error where it doesn't know what the mail() function even is—admittedly unlikely. Not too sure.
My guess is that your server is not even set up to send mail properly yet. That can be a complicated setup if you are running your own server. If you are on a shared server, it really should be set up already... unless your host is not very good.
In any case, if you are running in WordPress I'd recommend installing the Jetpack plugin by the folks who made WordPress itself. It includes a feature that adds a contact form to a page with a few clicks of your cursor.
If that form won't send an email, there is something wrong that is beyond the scope of the information you provided in your question.
<form class="form" method="post" action="index.php">
<p class="name">
<label for="name">Name</label>
<input type="text" name="name" id="name" placeholder="Enter your name" size="40" />
</p>
<p class="email">
<label for="email">Email</label>
<input type="text" name="email" id="email" placeholder="mail#example.com" size="40" />
</p>
<p class="web">
<label for="telephone">Telephone</label>
<input type="text" name="telephone" id="telephone" placeholder="000-000-000" size="40" />
</p>
<p class="text">
<label for="message">Message</label>
<textarea name="message" placeholder="Write something to us" cols="40" rows="5" /></textarea>
</p>
<p class="submit">
<input type="submit" name="submit" value="Send" />
<input type="reset" value="Cancel" />
</p>
</form>
AND YOUR index.php
<?php
if(isset($_POST['submit'] == 'Send')) {
$ToEmail = 'sample#sample.com';
$EmailSubject = 'Contact Form';
$mailheader = "From: " . $_POST["email"] . "\r\n";
$mailheader .= "Reply-To: " . $_POST["email"] . "\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = " <strong>Name:</strong> " . $_POST["name"] . "";
$MESSAGE_BODY .= "<br> <strong>Email:</strong> " . $_POST["email"] . "";
$MESSAGE_BODY .= "<br> <strong>Telephone:</strong> " . $_POST["telephone"] . "";
$MESSAGE_BODY .= "<br><br> <strong>Message:</strong> " . nl2br($_POST["message"]) . "";
$status = mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die("Failure");
}
if($status){
echo "your success message";
}
?>
try this
ONE MORE THING
Since you are using this on wordpress you should better use wp_mail funciton of wordpress
I have a form that sends its data to a process.php file for processing in that file I have the following code:
<?php
$name = $_GET['name'];
$number = $_GET['number'];
$email = $_GET['email'];
$comment = $_GET['message'];
$sales = $_POST['sales'];
$lettings = $_POST['lettings'];
$to = "me#me.com";
$subject = "New website registration";
$message = "Name: ".$name."\r\n";
if(isset($number) && $number!='')
$message.= "Number: ".$number."\r\n";
if(isset($email) && $email!='')
$message.= "Email: ".$email."\r\n";
if(isset($comment) && $comment!='')
$message.= "Comment: ".$comment."\r\n";
if(isset($sales))
{
$message.= "I am Interested in Sales" . "\r\n";
}else{
//
}
if(isset($lettings))
{
$message.= "I am Interested in Lettings";
}else{
//
}
$headers = "From: ".$name." <".$email.">";
$result = mail($to,$subject,$message,$headers);
return $result;
?>
The HTML for the form is as follows:
<form id="register_form" name="register" method="post" action="/content/contact/process.php">
<input type="text" id="name" name="name" class="regform" onFocus="if(this.value=='Name'){this.value='';}" onBlur="if(this.value==''){this.value='Name';}" value="Name" />
<input type="text" id="number" name="number" class="regform" onFocus="if(this.value=='Phone number'){this.value='';}" onBlur="if(this.value==''){this.value='Phone number';}" value="Phone number" />
<input type="text" id="email" name="email" class="regform" onFocus="if(this.value=='Email address'){this.value='';}" onBlur="if(this.value==''){this.value='Email address';}" value="Email address" />
<textarea id="message" name="message" class="regtext" onFocus="if(this.value=='Message'){this.value='';}" onBlur="if(this.value==''){this.value='Message';}">Message</textarea>
<label for"sales">Sales<input type="checkbox" name="sales" value="1" /></label>
<label for"sales">Lettings<input type="checkbox" name="lettings" value="1"/></label>
<input id="submit" type="submit" value="Submit" class="regsender" />
<div class="loading"></div>
</form>
When the checkboxes are checked, the expected messages do not come through in the email. Am I missing something here. I've tried several different approaches to getting this to work, none of which do. Any help would be appreciated. Thanks.
You are using method = POST and retrieving values with $_GET
I have updated your code check it
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$number = $_POST['number'];
$email = $_POST['email'];
$comment = $_POST['message'];
if (isset($_POST['sales']))
{
$sales = $_POST['sales'];
}
else if(isset($_POST['lettings']))
{
$lettings =$_POST['lettings'];
}
$to = "me#me.com";
$subject = "New website registration";
$message = "Name: ".$name."\r\n";
if(isset($number) && $number!='')
$message.= "Number: ".$number."\r\n";
if(isset($email) && $email!='')
$message.= "Email: ".$email."\r\n";
if(isset($comment) && $comment!='')
$message.= "Comment: ".$comment."\r\n";
if(isset($_POST['sales']))
{
$message.= "I am Interested in Sales" . "\r\n";
}
else if(isset($_POST['lettings']))
{
$message.= "I am Interested in Lettings";
}
echo $message;
$headers = "From: ".$name." <".$email.">";
$result = mail($to,$subject,$message,$headers);
return $result;
}
?>
<form id="register_form" name="register" method="post" action="testing_page.php">
<input type="text" id="name" name="name" class="regform" onFocus="if(this.value=='Name'){this.value='';}" onBlur="if(this.value==''){this.value='Name';}" value="Name" />
<input type="text" id="number" name="number" class="regform" onFocus="if(this.value=='Phone number'){this.value='';}" onBlur="if(this.value==''){this.value='Phone number';}" value="Phone number" />
<input type="text" id="email" name="email" class="regform" onFocus="if(this.value=='Email address'){this.value='';}" onBlur="if(this.value==''){this.value='Email address';}" value="Email address" />
<textarea id="message" name="message" class="regtext" onFocus="if(this.value=='Message'){this.value='';}" onBlur="if(this.value==''){this.value='Message';}">Message</textarea>
<label for"sales">Sales<input type="checkbox" name="sales" value="1" /></label>
<label for"sales">Lettings<input type="checkbox" name="lettings" value="1"/></label>
<input id="submit" name="submit" type="submit" value="Submit" class="regsender" />
<div class="loading"></div>
</form>