Sending email with multiple checkboxes using php - php

In this code i can't able to print the echo statement how can i able to know whether this code is sending mail or not. I'm a web designer not developer. if the echo statement is working means i can undestand that the code is working properly.
if(isset($_REQUEST['email']))
{
echo "dfsdkf";
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "info#ltnts.com";
$email_subject = "Enquiry Details From ltnt.in";
$customer_name=$_REQUEST['fullname'];
$organisation=$_REQUEST['cmp_name'];
$phone_num=$_REQUEST['contact'];
$email=$_REQUEST['logo_emailid'];
$country=$_REQUEST['country'];
$state=$_REQUEST['state'];
$city=$_REQUEST['logo_city'];
$zipcode=$_REQUEST['logo_zipcode'];
$project_type=$_REQUEST['market_type'];
$website_url=$_REQUEST['logo_name'];
$website_purpose=$_REQUEST['business_desc'];
$website_keyword=$_REQUEST['web_keyword'];
$Competitors=$_REQUEST['targent_aud'];
$sample_websites=$_REQUEST['targent_aud1'];
$no_of_updation=$_REQUEST['updation'];
$required_pages=$_REQUEST['checkbox'];
$additional_page=$_REQUEST['addition_page'];
$other_details=$_REQUEST['other_d'];
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Customer Name: ".clean_string($customer_name)."\n";
$email_message .= "organisation: ".clean_string($organisation)."\n";
$email_message .= "phone_num: ".clean_string($phone_num)."\n";
$email_message .= "Email ID: ".clean_string($email)."\n";
$email_message .= "Country: ".clean_string($country)."\n";
$email_message .= "state: ".clean_string($state)."\n";
$email_message .= "city: ".clean_string($city)."\n";
$email_message .= "zipcode: ".clean_string($zipcode)."\n";
$email_message .= "project_type: ".clean_string($project_type)."\n";
$email_message .= "website_url: ".clean_string($website_url)."\n";
$email_message .= "website_purpose: ".clean_string($website_purpose)."\n";
$email_message .= "website_keyword ID: ".clean_string($website_keyword)."\n";
$email_message .= "Competitors: ".clean_string($Competitors)."\n";
$email_message .= "sample_websites: ".clean_string($sample_websites)."\n";
$email_message .= "no_of_updation: ".clean_string($no_of_updation)."\n";
//$email_message .= "required_pages: ".clean_string($required_pages)."\n";
$email_message .= "additional_page: ".clean_string($additional_page)."\n";
$email_message .= "other_details: ".clean_string($other_details)."\n";
$newsletter = $_POST['checkbox'];
if ($newsletter != 'Yes')
{
$newsletter = 'No';
}
$email_message .="Selected:".clean_string($newsletter)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email_to."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
}
else
{
echo "dfjdhfjshfjz";
}
?>
<input name="checkbox[] "type="checkbox" name="page_Home" value="Home" id="pageHome" onChange="toggleVisibility('home');" /><label for="pageHome"> Home</label><img id="home" src="images/icon-tick.png" style="visibility:hidden"/><br/>
<input name="checkbox[]" value="About_us" id="page_Aboutus" type="checkbox" onChange="toggleVisibility('aboutus');"><label for="page_Aboutus"> About Us</label><img id="aboutus" src="images/icon-tick.png" style="visibility:hidden" /><br/>
<input name="checkbox[]" value="Services" id="pageServices" type="checkbox" onChange="toggleVisibility('services');"><label for="pageServices"> Services</label><img id="services" src="images/icon-tick.png" style="visibility:hidden" /><br/>
<input name="checkbox[]" value="Products" id="pageProducts" type="checkbox" onChange="toggleVisibility('products');"><label for="pageProducts"> Products</label><img id="products" src="images/icon-tick.png" style="visibility:hidden"/><br/>
<input name="checkbox[]" value="Enquiry" id="pageEnquiry" type="checkbox" onChange="toggleVisibility('enquiry');"><label for="pageEnquiry"> Enquiry</label><img id="enquiry" src="images/icon-tick.png" style="visibility:hidden"/><br/>
<input name="checkbox[]" value="Contact_us" id="pageContact" type="checkbox" onChange="toggleVisibility('Contact');"><label for="pageContact">Contact Us</label><img id="Contact" src="images/icon-tick.png" style="visibility:hidden" /><br/>

First check if $_REQUEST['email'] is set and in order to know if code is sending mail or not
You can use error_get_last(), when mail() returns false.
With print_r(error_get_last()) you get proper error
mail() returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
It is important to note that just because the mail was accepted for delivery, it does not mean the mail will reach the destination.
use #mail to suppress warnings
Use
if( #mail($email_to, $email_subject, $email_message, $headers) ) {
echo 'mail send';
} else {
print_r(error_get_last());
}

Related

PHP contact form sends message through senders address

Recently I've been having problems with my PHP contact form. It's worked great for about two years, and I haven't changed anything, so I don't really understand what the problem is. Here's the code:
<?php
// Check for header injections
function has_header_injection($str) {
return preg_match ( "/[\r\n]/", $str );
}
if(isset ($_POST['contact_submit'])) {
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$tel = trim($_POST['tel']);
$msg = $_POST['message'];
// check to see if name or email have header injections
if (has_header_injection($name) || has_header_injection($email)){
die();
}
if ( !$name || !$email || !$msg ) {
echo '<h4 class="error">All Fields Required</h4>Go back and try again';
exit;
}
// add the recipient email to a variable
$to = "example#example.net";
// Create a subject
$subject = "$name sent you an email";
// construct your message
$message .= "Name: $name sent you an email\r\n";
$message .= "Telephone: $tel\r\n";
$message .= "Email: $email\r\n\r\n";
$message .= "Message:\r\n$msg";
$message = wordwrap(message, 72);
// set the mail header
$headers = "MIME=Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "\r\nFrom: " . $name . " \r\n\r\n" . $tel . " \r\n\r\n " . $msg . "\r\n\r\n <" . $email . "> \r\n\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: high\r\n\r\n";
// Send the Email
mail( $to, $subject, $message, $headers );
?>
<!--- END PHP CONTACT FORM -->
<!-- Show Success message -->
<h2>Thanks for contacting Us!</h2>
<p align="center">Please allow 24 hours for a response</p>
<p>« Go to Home Page</p>
<?php } else { ?>
<form method="post" action="" id="contact-form">
<label for="name">Your Name</label>
<input type="text" id="name" name="name">
<label for="tel">Your Phone Number</label>
<input type="tel" id="tel" name="tel">
<label for="email">Your Email</label>
<input type="email" id="email" name="email">
<label for="message">the date/time you wish to sign up for</label>
<textarea id="message" name="message"></textarea>
<br>
<input type="submit" class="button next" name="contact_submit" value="Sign Up">
</form>
<?php } ?>
However, when the contact form is submitted, instead of sending the information to the body of the email, it sends it in the "From" section of the email. For example, the email might say:
To: Web Developer
From: Bob Smith 888-888-8888 mondays, wednesdays fridays
Subject: Bob Smith sent you an email!
Body:
X-Priority: 1X-MSMail-Priority: high
message
I don't really know what's going on, so any help would be appreciated!
You are adding all that info in the "from" header.
$headers .= "\r\nFrom: " . $name . " \r\n\r\n" . $tel . " \r\n\r\n " . $msg . "\r\n\r\n <" . $email . "> \r\n\r\n";
Change your headers to this:
$headers = "MIME=Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: {$name} <{$email}>\r\n"; // Removed all extra variables
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: high\r\n";
and it should work.
You are already sending the $message, containing all the above data in the body as well.
Why you haven't experienced this before is however a mystery.
NOTE: You only need to have one \r\n after each header.
You should also change this row:
$message = wordwrap(message, 72);
to
$message = wordwrap($message, 72); // Adding $ in front of the variable.

php mail function not working in my server [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am using PHP mail function to send a mail, But am testing my local sever mail has been sent but my live i cant sent mail. Can you please help me?
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: <'.$_POST['email'].'>' . "\r\n";
$to = "xxxxxxx#gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
} else {
echo "Cannot Send Email ";
}
Why use mail() when you have codeigniter email class.
$this->load->library('email');
$this->email->from('your#example.com', 'Your Name');
$this->email->to('someone#example.com');
$this->email->cc('another#another-example.com');
$this->email->bcc('them#their-example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
Use mandrillapp for sending mail using SMTP, and add credentials for email class.
Try it. It's Working
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: '.$_POST['email'].'' . "\r\n";
$CusHeaders .= 'Reply-To: '.$_POST['email'].'' . "\r\n";
$CusHeaders .= 'X-Mailer: PHP/' . phpversion();
$to = "xxxxxxx#gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
} else {
echo "Cannot Send Email ";
}
Use this as html(test)
<form action="#" method="post">
<input type="text" name="name" placeholder="name" />
<input type="text" name="email" placeholder="email"/>
<input type="text" name="phone" placeholder="phone" />
<input type="text" name="message" placeholder="message"/>
<input type="submit" name="submit"/>
</form>
PHP
if(isset($_POST[submit]))
{
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: <'.$_POST['email'].'>' . "\r\n";
$to = "p******#gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
}
else {
echo "Cannot Send Email ";
}
}
?>

PHP Message success function [HELP]

anyone help me with my contact form? it will not work, it sends a message but no confirmation of message succes? everything works fine exceptg the Message succesfull send function :(
here are the codes hope someone can help me
Contact.php
<?php
#error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
#ini_set('display_errors', true);
#ini_set('html_errors', true);
#ini_set('error_reporting', E_ALL ^ E_NOTICE ^ E_WARNING);
ini_set("log_errors", 1);
ini_set("error_log", "php-error.log");
error_log( "Hello, errors!" );
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "info#arjen079.com";
$email_subject = "Contact Application Website!";
$email_noreply = "noreply#arjen079.com";
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$subject = $_POST['subject']; // required
$message = $_POST['message']; // required
$email_message = "Form Details Below:\n\n";
$email_messagesender = "Here is a copy of the form you filled in:\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Subject: ".clean_string($subject)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
$email_messagesender .= "First Name: ".clean_string($name)."\n";
$email_messagesender .= "Email: ".clean_string($email)."\n";
$email_messagesender .= "Subject: ".clean_string($subject)."\n";
$email_messagesender .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
// send a copy to sender
$headers = 'From: '.$email_noreply."\r\n".
'Reply-To: '.$email_noreply."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email, "Thanks For contacting!", "Thanks for contacting me, I will reply to you shortly. \n\n----------------\n\n" . $email_messagesender, $headers);
echo 'Message Succesfully Sent!<script>$(\'response-message\').text(\'Message Succesfully Sent!\');var form = document.getElementById("contact-form");form.reset();</script>';
}
?>
Contact form:
<div class="container">
<div class="row">
<div class="span7">
<form action="http://www.arjen079.com/contact.php" method="post" class="contact-form" id="contact-form">
<h1>Contact</h1>
<hr class="fancy-hr">
<input type="text" name="name" placeholder="Name" class="required">
<input type="email" name="email" placeholder="Email" class="required">
<input type="text" name="subject" placeholder="Subject" class="required">
<textarea name="message" placeholder="Message" class="required"></textarea>
<div class="response-message"></div>
<input type="submit" value="Submit" name="submit" class="float-right">
<div class="clear"></div>
</form>
Thanks already! ;)
echo 'Message Succesfully Sent!<script>$(\'response-message\').text(\'Message Succesfully Sent!\');var form = document.getElementById("contact-form");form.reset();</script>';
The error is in this part.
$(\'response-message\') should be $(\'.response-message\').
Notice the . you're missing? You're trying to target the ELEMENT called response-message, not the div with the class of it.

Sending a form to email not working

I am trying to make a form that will be sent to my email. But it display errors on submission. Javascript to validate the form is not shown but it works fine.
I am not sure what's wrong with my code below, been trying to figure out all day and reading various threads but to no avail.
Below is my php code to handle the form.
<?php
if(isset($_POST['name'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "me#gmail.com";
$email_subject = "Nexwave Form";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
$name = $_POST['name']; // required
$designation = $_POST['designation'];
$company = $_POST['company'];
$contact = $_POST['contact'];
$email = $_POST['email']; // not required
$users = $_POST['users']; // required
$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Designation: ".clean_string($designation)."\n";
$email_message .= "company: ".clean_string($company)."\n";
$email_message .= "Contact ".clean_string($contact)."\n";
$email_message .= "email: ".clean_string($email)."\n";
$email_message .= "Number of Users: ".clean_string($users)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
echo (int) mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
Below is my html code:
<form name="form" action="send_mail.php" onSubmit="return validateForm();" method="POST">
Name<br/><input name="name" type="text" style="width:90%;"/><br/>
Designation<br/><input name="designation" type="text" style="width:90%;"/><br/>
Company<br/><input name="company" type="text" style="width:90%;"/><br/>
Contact Number<br/><input name="contact" type="text" style="width:90%;"/><br/>
Email<br/><input name="email" type="text" style="width:90%;"/><br/>
Number of Users<br/><input name="users" type="text" style="width:90%;"/>
<span style="text-align:right;display:block;width:174px;"><input style="height:25px;margin-top:20px;margin-bottom:10px;background-color:#ffffff;border:0;color:#009110;" type="submit" class="submit" value="Submit" /></span>
</form>
below is the error:
This is what i get even after changing the email_address and email_from.
"; echo $error."
"; echo "Please go back and fix these errors.
"; die(); } $name = $_POST['name']; // required $designation = $_POST['designation']; $company = $_POST['company']; $contact = $_POST['contact']; $email = $_POST['email']; // not required $users = $_POST['users']; // required $error_message = ""; $string_exp = "/^[A-Za-z .'-]+$/"; $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Designation: ".clean_string($designation)."\n"; $email_message .= "company: ".clean_string($company)."\n"; $email_message .= "Contact ".clean_string($contact)."\n"; $email_message .= "email: ".clean_string($email)."\n"; $email_message .= "Number of Users: ".clean_string($users)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); echo (int) mail($email_to, $email_subject, $email_message, $headers); ?> Thank you for contacting us. We will be in touch with you very soon.
your help is very much appreciated
You have many errors present in this script as mentioned by question comments above.
email form name email_address is not the same as $_POST['email']
you are not defining $email_from before you call it.
I would do some simple testing before posting a question like this and try to echo out all the variables one by one and see what you get. This would show you the two mentioned errors. And if you cannot solve it and still have errors then please post your error message so others can be of more assistance than just it doesn't work.

Form submission and mail send

I have made a form for registration by php .The form has submitter email address field.I want that after form submission , form content will send to both form submitter and admin via submitter email address and admin email address. Submitter email address will get from submitter email address field.Admin email address is fixed .
For Submitter
headers= "from : no-reply#eschool.com"
messagebody same as it is
For admin
headers=" from :$email"
messagebody same as it is
I tried to do this:
Html code:
<form action="action.php" method="post">
<table>
<tr>
<td>Name</td>
<td>:</td>
<td><input type="text" name="name" width="400" /></td>
</tr>
<tr>
<td>Address</td>
<td>:</td>
<td><input type="text" name="address" width="400" /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input type="text" name="email" width="400" /></td>
</tr>
<tr>
<td>Password</td>
<td rowspan="2"> </td>
<td>
<p><input type="text" name="pass" width="400" /></p>
<p> </p>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="insert" value="Insert" /></td>
</tr>
</table>
<input type="submit" value="submit" />
</form>
action.php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
$to = $email . "," . $admin;
$email_message .= "Name: ". $name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type:text/plain;charset=UTF-8;" . "\n";
$headers .= "content-Transfer-encoding: 8bit" ."\n";
$headers .= "From: no-reply#eschool.com ". "\n";
mail($to, $subject, $email_message, $headers);
Thanks
Your code is perfect, what is your are facing problem, plz write your problem.
Make following change in action.php for your convenience :
<?php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
//$to = $email $admin;
$email_message = '';
$email_message .= "Name: ". $name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers1 = 'MIME-Version: 1.0' . "\r\n";
$headers1 .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$headers1 .= "From: no-reply#eschool.com ". "\n";
$headers2 = 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$headers2 .= "From: ". $email . "\n";
if(#mail( $email, $subject, $email_message , $headers1 )) {
#mail( $admin, $subject, $email_message , $headers2 )
echo "Mail Sent.";
} else {
echo "Mail Not Sent.";
}
?>
You can simply make two different versions of your headers and execute mail(...) twice:
<?php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
$email_message = "Name: ".$name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type:text/plain;charset=UTF-8;\n";
$headers .= "content-Transfer-encoding: 8bit\n";
$poster_headers = $headers . "From: no-reply#eschool.com\n";
$admin_headers = $headers . "From: ".$email."\n";
mail( $admin, $subject, $email_message, $admin_headers );
mail( $email, $subject, $email_message, $poster_headers );
?>

Categories