Send checkbox value to email - php

I have three checkboxes for requesting catalogs. I would like to get value for all three of them in each email.
Here is my HTML:
<input type="checkbox" name="catalog" value="Grower"/> Grower Supply Catalog <br><br>
<input type="checkbox" name="catalog" value="Specialty"/> Specialty Catalog<br><br>
<input type="checkbox" name="catalog" value="Plant"/> Plant Source Catalog
Here is my PHP:
$name = #$_POST["name"];
$email = #$_POST["email"];
$street = #$_POST["street"];
$city = #$_POST["city"];
$state = #$_POST["state"];
$zip = #$_POST["zip"];
$email = #$_POST["email"];
$phone = #$_POST["phone"];
$message = #$_POST["comment"];
$catalog =#$_POST["catalog"];
foreach($_POST['catalog'] as $value) {
$check_msg .= "Checked: $value\n";
}
$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;
$mailBody = "You have been contacted by $name" . PHP_EOL . PHP_EOL;
$mailBody .= (!empty($company))?'Company: '. PHP_EOL.$company. PHP_EOL . PHP_EOL:'';
$mailBody .= (!empty($quoteType))?'project Type: '. PHP_EOL.$quoteType. PHP_EOL . PHP_EOL:'';
$mailBody .= "Street :" . PHP_EOL;
$mailBody .= $street . PHP_EOL . PHP_EOL;
$mailBody .= "City :" . PHP_EOL;
$mailBody .= $city . PHP_EOL . PHP_EOL;
$mailBody .= "State :" . PHP_EOL;
$mailBody .= $state . PHP_EOL . PHP_EOL;
$mailBody .= "Zip :" . PHP_EOL;
$mailBody .= $zip . PHP_EOL . PHP_EOL;
$mailBody .= "Phone :" . PHP_EOL;
$mailBody .= $phone . PHP_EOL . PHP_EOL;
$mailBody .= $check_msg .= "Catalog : $catalog\n";
$mailBody .= "Message :" . PHP_EOL;
$mailBody .= $message . PHP_EOL . PHP_EOL;
$mailBody .= "You can contact $name via email, $email.";
$mailBody .= (isset($phone) && !empty($phone))?" Or via phone $phone." . PHP_EOL . PHP_EOL:'';
if(mail($to, $subject, $mailBody, $headers)){
echo '<div class="alert alert-success">Success! Your message has been sent.</div>';
}
}
How can I send the checkbox values to email?

Use array syntax for those element names to send those values as an array:
<input type="checkbox" name="catalog[]" value="Grower"/> Grower Supply Catalog <br><br>
<input type="checkbox" name="catalog[]" value="Specialty"/> Specialty Catalog<br><br>
<input type="checkbox" name="catalog[]" value="Plant"/> Plant Source Catalog

I think You Should type properly foreach() method, type in camelCase Like this forEach()

Related

PHP form giving Errors

This is my PHP code which I'm using and Error is coming between the First Echo command in the code. Can anyone please Help?
<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["name"]==""||$_POST["email"]==""||$_POST["phone_number"]==""||$_POST["city"]==""||$_POST["gre_score"]==""||$_POST["toefl_score"]==""||$_POST["eng_marks"]==""||$_POST["country"]==""||$_POST["course_type"]==""||$_POST["department"]==""||$_POST["exp"]==""||$_POST["ug_details"]==""||$_POST["pg_details"]){
echo "Something Went Please Try Again!";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['email'];
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Invalid Sender's Email";
}
else{
$name = '$name';
$subject = 'Registration Form';
$headers = 'From: '. $email . "\r\n"; // Sender's Email
$headers .= 'Cc:'. $email . "\r\n"; // Carbon copy to Sender
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Phone Number:</strong> </td><td>" . strip_tags($_POST['phone_number']) . "</td></tr>";
$message .= "<tr><td><strong>City: </strong></td><td>" . strip_tags($_POST['city']) . "</td></tr>";
$message .= "<tr><td><strong>GRE Score:</strong> </td><td>" . strip_tags($_POST['gre_score']) . "</td></tr>";
$message .= "<tr><td><strong>TOEFL/IELTS Score:</strong> </td><td>" . strip_tags($_POST['toefl_score']) .
"";
$message .= "Engineering Marks: " . strip_tags($_POST['eng_marks']) .
"";
$message .= "Country Planning: " . strip_tags($_POST['country']) . "";
$message .= "Department: " . strip_tags($_POST['department']) . "";
$message .= "Job Experience: " . strip_tags($_POST['exp']) . "";
$message .= "Under Graduation Details: " . strip_tags($_POST['ug_details']) .
"";
$message .= "Post Graduation Details:" . strip_tags($_POST['pg_details']) .
"";
$message .= "Course Selected: " . strip_tags($_POST['course_type']) .
"";
$message .= "</body></html>";
// Send Mail By PHP Mail Function
mail("yash119ambaskar#gmail.com", $subject, $message, $headers);
echo "Your mail has been sent successfuly ! You will be contacted Shortly!";
}
}
}
?>
Hello Syntax error in your first if condition.Your post pg_details, you have not compare it with empty string.
if($_POST["name"]==""||$_POST["email"]==""||$_POST["phone_number"]==""||$_POST["city"]==""||$_POST["gre_score"]==""||$_POST["toefl_score"]==""||$_POST["eng_marks"]==""||$_POST["country"]==""||$_POST["course_type"]==""||$_POST["department"]==""||$_POST["exp"]==""||$_POST["ug_details"]==""||$_POST["pg_details"] == ""){

Customize a Php mail with html

I want to customize an php email with some html but I'm struggling with that...
After submit my form i receive the email but happen this
I was following this tutorial
I put the code i used.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Alright, lets send the email already!
if ( empty( $errorString ) ) {
$mailbody .= '<html><body>';
$mailbody .= '<img src="//http://xxxx/xxxxx/wp-content/uploads/2015/06/email.jpg" alt="Website Change Request" />';
$mailbody .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$mailbody .= __('Nome:', 'ci_theme' ) . ' ' . $clientname . "\n";
$mailbody .= __('Email:', 'ci_theme' ) . ' ' . $email . "\n";
$mailbody .= __('Chegada:', 'ci_theme' ) . ' ' . $arrive . "\n";
$mailbody .= __('Saída:', 'ci_theme' ) . ' ' . $depart . "\n";
$mailbody .= __('Adultos:', 'ci_theme' ) . ' ' . $guests . "\n";
$mailbody .= __('Crianças:', 'ci_theme' ) . ' ' . $children . "\n";
$mailbody .= __('Quarto:', 'ci_theme' ) . ' ' . $room->post_title . "\n";
$mailbody .= __('Mensagem:', 'ci_theme' ) . ' ' . $message . "\n";
$mailbody .= __('Hora do Check-in (hh:mm):', 'ci_theme' ) . ' ' . $timeguest . "\n";
$mailbody .= __('Contacto:', 'ci_theme' ) . ' ' . $contactguest . "\n";
$mailbody .= __('Autorização:', 'ci_theme' ) . ' ' . $autorizo . "\n";
$mailbody .= __('Cama Extra:', 'ci_theme' ) . ' ' . $camaextra . "\n";
$mailbody .= "</table>";
$mailbody .= "</body></html>";
mail($to, $mailbody, $headers);
// If you want to receive the email using the address of the sender, comment the next $emailSent = ... line
// and uncomment the one after it.
// Keep in mind the following comment from the wp_mail() function source:
/* If we don't have an email from the input headers default to wordpress#$sitename
* Some hosts will block outgoing mail from this address if it doesn't exist but
* there's no easy alternative. Defaulting to admin_email might appear to be another
* option but some hosts may refuse to relay mail from an unknown domain. See
* http://trac.wordpress.org/ticket/5007.
*/
//$emailSent = wp_mail(ci_setting('booking_form_email'), get_option('blogname').' - '. __('Booking form', 'ci_theme'), $mailbody);
$emailSent = wp_mail(ci_setting('booking_form_email'), get_option('blogname').' - '. __('Formulário de Reserva','theme-text-domain', 'ci_theme'), $mailbody, 'From: "'.$clientname.'" <'.$email.'>');
$emailSent2 = wp_mail( $email, __('Booking Inquiry','theme-text-domain', 'ci_theme'), __('Thank you so much for your interest in Hotel Aveiro Center! We will get back to you within 24 hours to answer your request.','theme-text-domain','ci_theme'),'From: Hotel Aveiro Center <xxxx#xxxx>');
}
Here is a simple example I have done .
//build email to be sent
$to = $email;
$subject = $site_url;
$subject .= ": Activate Your Account";
$message = "
<html>
<head>
<title>Account Activation</title>
</head>
<body>
<h3>Account Activation</h3>
<p>Dear ".$user.", thank you for registering at ".$site_url.".</p>
<p>Please click on the link below to activate your account:</p>
<a href='".$site_url."/confirm_user_reg.php?activation_key=".$activation_key."'>http://www.".$site_url."</a>.
<p>If the above link does not work, copy and paste the below URL to your browser's address bar:</p>
<p><i>http://www.".$site_url."/confirm_user_reg.php?activation_key=".$activation_key."</i></p><br/>
<p>If you did not initiate this request, simply disregard this email, and we're sorry for bothering you.</p>
<br/><br/>
<p>Sincerely,</p>
<p>The ".$site_url." Team.</p>
</body>
</html>
";
// To send HTML mail, the Content-type header must be set
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

Images not sent to inbox, using PHP mail()

I have an online property submission area in my website which lets users send properties in the form of text with images, to my email address:
But I'm not receiving the images. I only receive the text. I am trying to figure out why this is happening, but I couldn't find out anything that would cause this. Can someone help me find out the issue?
Code:
<?php
if (isset($_POST['propertystatus'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "contact#scale-property.com";
$email_subject = "New Property From Customer";
$email_subject_to_user = "Copy of your email";
$propery_Information = 'PROPERTY INFORMATION';
$propery_Location = 'PROPERTY LOCATION';
$contact_Information = 'CONTACT INFORMATION';
function died($error)
{
// your error code can go here
echo "We are very sorry, but there were errors found with the form you submitted.<br>";
echo $error . "<br />";
die();
}
// validation expected data exists
if (!isset($_POST['propertystatus']) || !isset($_POST['currencytype']) || !isset($_POST['currency']) || !isset($_POST['rooms']) || !isset($_POST['bathroom']) || !isset($_POST['kitchen']) || !isset($_POST['yard']) || !isset($_POST['housedesproperty']) || !isset($_POST['drop_1']) || !isset($_POST['drop_2']) || !isset($_POST['drop_3']) || !isset($_POST['region']) || !isset($_POST['street']) || !isset($_POST['name']) || !isset($_POST['emailadd']) || !isset($_POST['conemailadd']) || !isset($_POST['phone1']) || !isset($_POST['phone2']) || !isset($_FILES['uploadimages'])) {
died('You have not properly selected the fields.');
}
// start code of attachement
if (empty($_FILES['uploadimages']['name'])) {
echo 'You have\'nt Entered Value for upload field';
exit();
} else {
$attachment = $_FILES['uploadimages']['tmp_name'];
$attachment_name = $_FILES['uploadimages']['name'];
if (is_uploaded_file($attachment)) {
$fp = fopen($attachment, "rb");
$data = fread($fp, filesize($attachment));
$data = chunk_split(base64_encode($data));
fclose($fp);
}
$headers = "From: $email<$email>\n";
$headers .= "Reply-To: <$email>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n";
$headers .= "X-Mailer: PHP4\n";
$headers .= "X-Priority: 3\n";
$headers .= "Return-Path: <$email>\n";
$headers .= "This is a multi-part message in MIME format.\n";
$headers .= "------=MIME_BOUNDRY_main_message \n";
$headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n";
$message = "------=MIME_BOUNDRY_message_parts\n";
$message .= "Content-Type: text/html; charset=\"utf-8\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n";
$message .= "\n";
$message .= "------=MIME_BOUNDRY_message_parts--\n";
$message .= "\n";
$message .= "------=MIME_BOUNDRY_main_message\n";
$message .= "Content-Type: application/octet-stream;\n\tname=\"" . $attachment_name . "\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment;\n\tfilename=\"" . $attachment_name . "\"\n\n";
$message .= $data; //The base64 encoded message
$message .= "\n";
$message .= "------=MIME_BOUNDRY_main_message--\n";
mail($email_to, $email_subject, $message, $headers);
}
// end code of attachment
$property_status = $_POST['propertystatus']; // required
$currency_type = $_POST['currencytype']; // required
$currency = $_POST['currency']; // required
$rooms = $_POST['rooms']; // required
$bathroom = $_POST['bathroom']; // required
$kitchen = $_POST['kitchen']; // required
$yard = $_POST['yard']; // required
$housedesproperty = $_POST['housedesproperty']; // required
$drop_1 = $_POST['drop_1']; // required
$drop_2 = $_POST['drop_2']; // required
$drop_3 = $_POST['drop_3']; // required
$region = $_POST['region']; // required
$street = $_POST['street']; // required
$name = $_POST['name']; // required
$emailadd = $_POST['emailadd']; // required
$conemailadd = $_POST['conemailadd']; // required
$phone1 = $_POST['phone1']; // required
$phone2 = $_POST['phone2']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if (!preg_match($email_exp, $emailadd) && !preg_match($email_exp, $conemailadd)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$email_message = "Property details below.\n\n";
function clean_string($string)
{
$bad = array(
"content-type",
"bcc:",
"to:",
"cc:",
"href"
);
return str_replace($bad, "", $string);
}
$email_message .= "" . clean_string($propery_Information) . "\n";
$email_message .= "--------------------------------------------" . "\n";
$email_message .= "Property Status: " . clean_string($property_status) . "\n";
$email_message .= "Total Price: " . clean_string($currency_type) . " " . (number_format($currency, 2, '.', ',')) . "\n";
$email_message .= "Rooms: " . clean_string($rooms) . "\n";
$email_message .= "Bathrooms: " . clean_string($bathroom) . "\n";
$email_message .= "Bathrooms: " . clean_string($kitchen) . "\n";
$email_message .= "Bathrooms: " . clean_string($yard) . "\n";
$email_message .= "Description: " . clean_string($housedesproperty) . "\n\n";
$email_message .= "" . clean_string($propery_Location) . "\n";
$email_message .= "--------------------------------------------" . "\n";
$email_message .= "Province: " . clean_string($drop_1) . "\n";
$email_message .= "District: " . clean_string($drop_2) . "\n";
$email_message .= "PD(Nahya): " . clean_string($drop_3) . "\n";
$email_message .= "Bathrooms: " . clean_string($region) . "\n";
$email_message .= "Street: " . clean_string($street) . "\n\n";
$email_message .= "" . clean_string($contact_Information) . "\n";
$email_message .= "--------------------------------------------" . "\n";
$email_message .= "Name: " . clean_string($name) . "\n";
$email_message .= "Email ID: " . clean_string($emailadd) . "\n";
$email_message .= "Con-Email ID: " . clean_string($conemailadd) . "\n";
$email_message .= "Phone(1): " . clean_string($phone1) . "\n";
$email_message .= "Phone(2): " . clean_string($phone2) . "\n";
// create email headers
$headers = 'From: ' . $emailadd . "\r\n" . 'Reply-To: ' . $emailadd . "\r\n" . 'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
#mail($emailadd, $email_subject_to_user, $email_message, "From: $email_to");
?>
<!-- include your own success html here -->
Your Property has been Posted please check your email address.
<?php
}
?>
Try this,this for multiple image attachment
http://www.emanueleferonato.com/2008/07/22/sending-email-with-multiple-attachments-with-php/

Emailing form data in CSV file format

I have a rather large form that when filled out and submitted, I want the data to be formed into a CSV file and emailed to a specific email address.
Does anyone know if it is all at all possible to add a file upload function to the bottom of this form?
This is for a client and have just encountered limitations in my knowledge of PHP.
This is the code I am using:
<?php
if(isset($_POST['formSubmit'])) {
$email=$_REQUEST['email'];
$firstName=$_REQUEST['firstName'];
$lastName=$_REQUEST['lastName'];
$to = "***#***.co.uk";
$subject = "New application submission";
$message = "".
"Email: $email" . "\n" .
"First Name: $firstName" . "\n" .
"Last Name: $lastName";
//The Attachment
$varTitle = $_POST['formTitle'];
$varForname = $_POST['formForname'];
$varMiddlename = $_POST['formMiddlename'];
$varSurname = $_POST['formSurname'];
$varKnownas = $_POST['formKnownas'];
$varAdressline1 = $_POST['formAdressline1'];
$varAdressline2 = $_POST['formAdressline2'];
$varAdressline3 = $_POST['formAdressline3'];
$varAdressline4 = $_POST['formAdressline4'];
$varAdressline5 = $_POST['formAdressline5'];
$varPostcode = $_POST['formPostcode'];
$varTelephone = $_POST['formTelephone'];
$varMobile = $_POST['formMobile'];
$varEmail = $_POST['formEmail'];
$varApproval = $_POST['formApproval'];
$varothersurname = $_POST['formothersurname'];
$varsex = $_POST['formsex'];
$varninumber = $_POST['formninumber'];
$varjobtitle = $_POST['formjobtitle'];
$vardates = $_POST['formdates'];
$varresponsibilities = $_POST['formresponsibilities'];
$varjobtitle2 = $_POST['formjobtitle2'];
$vardates2 = $_POST['formdates2'];
$varresponsibilities2 = $_POST['formresponsibilities2'];
$varjobtitle3 = $_POST['formjobtitle3'];
$vardates3 = $_POST['formdates3'];
$varresponsibilities3 = $_POST['formresponsibilities3'];
$varwebsite = $_POST['formwebsite'];
$vartshirt = $_POST['formtshirt'];
$vardietary = $_POST['formdietary'];
$varpc = $_POST['formpc'];
$varmac = $_POST['formmac'];
$varlaptop = $_POST['formlaptop'];
$vardongle = $_POST['formdongle'];
$varediting = $_POST['formediting'];
$varsocial = $_POST['formsocial'];
$varphotography = $_POST['formphotography'];
$varfilming = $_POST['formfilming'];
$vartraining = $_POST['formtraining'];
$varexhibition = $_POST['formexhibition'];
$varspecial = $_POST['formspecial'];
$varhobbies = $_POST['formhobbies'];
$varphotography = $_POST['formphotography'];
$varfilming = $_POST['formfilming'];
$vartraining = $_POST['formtraining'];
$varexcel = $_POST['formexcel'];
$varbigpicture = $_POST['formbigpicture'];
$varcriminal = $_POST['formcriminal'];
$attachments[] = Array(
'data' => $data,
'name' => 'application.csv',
'type' => 'application/vnd.ms-excel' );
//Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
//Add the headers for a file attachment
$headers = "MIME-Version: 1.0\n" .
"From: {$from}\n" .
"Cc: davidkirrage#gmail.com\n".
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
//Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$text . "\n\n";
//Add sttachments
foreach($attachments as $attachment){
$data = chunk_split(base64_encode($attachment['data']));
$name = $attachment['name'];
$type = $attachment['type'];
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" ;
$message = "--{$mime_boundary}--\n";
mail($to, $subject, $message, $headers);
header('Location: http://bigpictest.co.uk/thanks.php');
exit();
}
}
?>
There is no need to go to so much trouble.
The following will probably help:
$filename="directory/csvfile.csv"; //specify filename and path
$keys=array_keys($_POST); //get list of post keys
$file=fopen($filename,"w"); //open a csv file to write to;
fputcsv($file,$keys); //write post keys as first line of CSV file.
fputcsv($file,$_POST); //write post data as second line of csv file.
fclose($file); //close the file.
The csv file you need to attach is created thus. No need for all those variables.
I haven't checked your mail code. If you are having problems with attaching the file, please ask a different question about that (though there are doubtless answers here already)
Good luck!
I've done this in asp and asp.net but never had to do it with php (that is sending mail with attachments from the server).
The thing to understand is that when you submit the form, the data is being sent to be processed somewhere, lets say: FormProcessor which may be in a separate file or in the php page itself.
So when the FormProcessor receives the data, you can combine it or format it in anyway you like.
You would need access to the filesystem to create the file on the server.
Let's say that the function for sending email is in the FormProcessor scope.
You can use email headers to add the attachment when you define the email object.
This is one of my send email funcitons in php which I've modified to use as a sample here:
function FormProcessor_SendEmail($v){ // $v is an array containing the data to use for sending the email
// parameters = $v[0] = user email, $v[1] = business name,
// $v[2] = address, $v[3] = city, $v[4] = state, $v[5] = zip code,
// $v[6] = phone, $v[7] = message, $v[8] = service area
$eol = "\r\n";
$tb = "\t";
$stb = "\t\t";
// notify new registrant
$to = $v[0];
$subject = "This is the subject text";
$message = "Date : " . $this->prepare_new_timestamp() . ".<br /><br />" . $eol;
$message .= "Thank you for requesting more information about " . $this->get_sitename() . "<br /><br />" . $eol;
$message .= "We will be contacting you as soon as possible<br />" . $eol;
$message .= "with information that is tailored to your needs and interests.<br /><br />" . $eol;
$message .= "We have received the following information from you:<br /><br />" . $eol;
$message .= "Your Business Name: " . $v[1] . "<br />" . $eol;
$message .= "Business Address: " . $v[2] . "<br />" . $eol;
$message .= "City: " . $v[3] . "<br />" . $eol;
$message .= "State: " . $v[4] . "<br />" . $eol;
$message .= "Zip Code: " . $v[5] . "<br />" . $eol;
$message .= "Phone: " . $v[6] . "<br />" . $eol;
$message .= "Service Area: " . $v[8] . "<br />" . $eol;
$message .= "Message: <br />" . $v[7] . "<br /><br />" . $eol;
$message .= "If you have additional questions, please address them to: " . $this->get_support_email() . "<br />" . $eol;
$message .= "or by phone at: " . $this->get_support_phone() . "<br /><br />" . $eol;
$message .= "If you did not submit this request, please contact us and let us know<br />" . $eol;
$message .= "so that we may take the proper actions necessary.<br /><br />" . $eol;
$message .= "Sincerely,<br />" . $eol;
$message .= "The Team at " . $this->get_sitename() . "<br />" . $eol;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: sitename <' . $this->get_webmaster_email() . '>' . "\r\n";
$headers .= 'Cc: webmaster <' . $this->get_webmaster_email() . '>' . "\r\n";
mail($to,$subject,$message,$headers);
return 1;
}
It doesn't send an attachment, but I'm sure someone else on this site can help you find a better way.
Hope it helps.

sending all data from email with require field

I'm creating a user require form in my site. For this I put some validation on compulsory fields, and when a user fills in the form and presses submit and validation is correct then I receive a email on my email address.
But now I would like all user information in the email, like name, city, budget etc... so what changes do I need to make in my email.php script?
If some fields are not compulsory and the user doesn't fill them in, can they affect my script?
My script is:
<?php
$to = "test#networkers.in";
$subject = "a new requiremnet come!";
$message = "Hi,\n\nyou get a new require";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "Sender-IP: " . $_SERVER["SERVER_ADDR"] . "\r\n";
$headers .= "From: " . stripslashes($name) . " <" . $email . ">" . "\r\n";
$headers .= "Priority: normal" . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
$sent = mail($to, $subject, $message, $headers) ;
if ($sent) {
echo "Your mail was sent successfully";
} else {
echo "We encountered an error sending your mail";
}
?>
and the data I recieve is:
$name = $_POST['fname'].' '.$_POST['lname'];
$email = $_POST['mail'];
$phone = $_POST['ph'];
$country = $_POST['country'];
$pt = $_POST['pt'];
$cwl = $_POST['cwl'];
$dyhyows = $_POST['dyhyows'];
$pb = $_POST['pb'];
$bpd = $_POST['bpd'];
$hdyhau = $_POST['hdyhau'];
You can add fields to the message body by concatenating them like so:
$message = "Hi,\n\nyou get a new require";
$message .= "\n Name: " . $name;
$message .= "\n Email: " . $email;
$message .= "\n Phone: " . $phone;
$message .= "\n Country: " . $country;
$message .= "\n pt: " . $pt;
$message .= "\n cwl: " . $cwl;
$message .= "\n dyhyows: " . $dyhyows;
$message .= "\n pb: " . $pb;
$message .= "\n bpd: " . $bpd;
$message .= "\n hdyhau: " . $hdyhau
Any fields that weren’t filled in by the user will simply be blank.

Categories