PHP form giving Errors - php

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"] == ""){

Related

Auto mail isn't executing HTML tags when inserted in between email body

I have a code to make and get an auto-email from the user when he submits the form.
The code also consists of insert query to put all the data into a DB table.
However, the Insert query and auto mail work fine. data gets inserted and I receive the mail with values as well.
The code goes for that as:
<?php include('db.php'); ?>
<?php
$fname = $_POST['fname'];
$mname = $_POST['mname'];
$lname = $_POST['lname'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$country = $_POST['country'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$altphone = $_POST['altphone'];
$citizenship = $_POST['citizenship'];
$visa = $_POST['visa'];
$inviteletter = $_POST['inviteletter'];
$housingassist = $_POST['housingassist'];
$im = $_POST['im'];
$status = 'open';
$university = $_POST['university'];
$univstartdate = $_POST['univstartdate'];
$univgraddate = $_POST['univgraddate'];
$univaddress = $_POST['univaddress'];
$univcity = $_POST['univcity'];
$univstate = $_POST['univstate'];
$univzipcode = $_POST['univzipcode'];
$univcountry = $_POST['univcountry'];
$usmle = implode(', ', $_POST['usmle']);
$rotationlength = $_POST['rotationlength'];
$speciality1 = $_POST['speciality1'];
$speciality2 = $_POST['speciality2'];
$speciality3 = $_POST['speciality3'];
$research = $_POST['research'];
$additional = $_POST['additional'];
$startdate = $_POST['startdate'];
$freecall = $_POST['freecall'];
$howus = $_POST['howus'];
$date = date_default_timezone_set('America/New_York');
$date = date('M-d,Y H:i:s');
$date2 = date('M-d,Y');
$conn = new mysqli ($servername, $dbusername, $dbpassword, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO applications (fname, mname, lname, address, address2, city, state, zipcode, country, email, phone, altphone, citizenship, visa, inviteletter, housingassist, im, university, univstartdate, univgraddate, univaddress, univcity, univstate, univzipcode, univcountry, usmle, rotationlength, speciality1, speciality2, speciality3, research, additional, startdate, freecall, howus, date, status)
VALUES ('$fname', '$mname', '$lname', '$address', '$address2', '$city', '$state', '$zipcode', '$country', '$email', '$phone', '$altphone', '$citizenship', '$visa', '$inviteletter', '$housingassist', '$im', '$university', '$univstartdate', '$univgraddate', '$univaddress', '$univcity', '$univstate', '$univzipcode', '$univcountry', '$usmle', '$rotationlength', '$speciality1', '$speciality2', '$speciality3', '$research', '$additional', '$startdate', '$freecall', '$howus', '$date2', '$status')";
if ($conn->query($sql) === TRUE) {
$email_from = 'newyorkrotations#gmail.com';//<== update the email address
$email_subject = "Student Application";
$email_body = "First Name : $fname.\n
Middle Name : $mname.\n
Last Name : $lname.\n
Address : $address.\n
Alt Address : $address2.\n
City : $city.\n
State : $state.\n
Zipcode : $zipcode.\n
Country : $country.\n
Email : $email.\n
Phone : $phone.\n
Alt Phone : $altphone.\n
Citizenship : $citizenship.\n
Does He Need Visa : $visa.\n
Does He Need Invite Letter : $inviteletter.\n
Does He Need Housing Assistance : $housingassist.\n
He is A : $im.\n
University : $university.\n
College Start Date : $univstartdate.\n
Graduation Date : $univgraddate.\n
University Address : $univaddress.\n
University City : $univcity.\n
University Stqate : $univstate.\n
University Zipcode : $univzipcode.\n
University Country : $univcountry.\n
Did He took Any Steps : $usmle.\n
Requested Rotation Length : $rotationlength.\n
Speciality #1 : $speciality1.\n
Speciality #2 : $speciality2.\n
Speciality #3 : $speciality3.\n
Research : $research.\n
Additional Services : $additional.\n
Rotation Start Date : $startdate.\n
Do He need physician's Free call : $freecall.\n
How did He Reached Us : $howus.\n
Application Submitted at : $date2.\n";
$to = "newyorkrotations#gmail.com";//<== update the email address
$headers = "From: $email \r\n";
$headers .= "Reply-To: $email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: index.php');
}
else {
echo "ERROR" . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
However I tried with adding some HTML code in to the code so that the mail i recieve look a bit nice. But instead i get the whole code as it is in my mail . Mean the HTML gets posted to mail as just plain text.
THe code for that as:
$email_from = 'newyorkrotations#gmail.com';//<== update the email address
$email_subject = "Student Application";
$message = '<html><body>';
$message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>First Name:</strong> </td><td>" . strip_tags($_POST['fname']) . "</td></tr>";
$message .= "<tr><td><strong>Middle Name:</strong> </td><td>" . strip_tags($_POST['mname']) . "</td></tr>";
$message .= "<tr><td><strong>Last Name:</strong> </td><td>" . strip_tags($_POST['lname']) . "</td></tr>";
$message .= "<tr><td><strong>Address:</strong> </td><td>" . strip_tags($_POST['address']) . "</td></tr>";
$message .= "<tr><td><strong>Alt Address:</strong> </td><td>" . strip_tags($_POST['address2']) . "</td></tr>";
$message .= "<tr><td><strong>City:</strong> </td><td>" . strip_tags($_POST['city']) . "</td></tr>";
$message .= "<tr><td><strong>State:</strong> </td><td>" . strip_tags($_POST['state']) . "</td></tr>";
$message .= "<tr><td><strong>ZipCode:</strong> </td><td>" . strip_tags($_POST['zipcode']) . "</td></tr>";
$message .= "<tr><td><strong>Country:</strong> </td><td>" . strip_tags($_POST['country']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Phone:</strong> </td><td>" . strip_tags($_POST['phone']) . "</td></tr>";
$message .= "<tr><td><strong>Alt Phone:</strong> </td><td>" . strip_tags($_POST['altphone']) . "</td></tr>";
$message .= "<tr><td><strong>Citizenship:</strong> </td><td>" . strip_tags($_POST['citizenship']) . "</td></tr>";
$message .= "<tr><td><strong>Does He Have Visa:</strong> </td><td>" . strip_tags($_POST['visa']) . "</td></tr>";
$message .= "<tr><td><strong>Does He Need Invite Letter:</strong> </td><td>" . strip_tags($_POST['inviteletter']) . "</td></tr>";
$message .= "<tr><td><strong>Does He Need Housing Assist:</strong> </td><td>" . strip_tags($_POST['housingassist']) . "</td></tr>";
$message .= "<tr><td><strong>He Is:</strong> </td><td>" . strip_tags($_POST['im']) . "</td></tr>";
$message .= "<tr><td><strong>University Name:</strong> </td><td>" . strip_tags($_POST['university']) . "</td></tr>";
$message .= "<tr><td><strong>University Start Date:</strong> </td><td>" . strip_tags($_POST['univstartdate']) . "</td></tr>";
$message .= "<tr><td><strong>University Graduation Date:</strong> </td><td>" . strip_tags($_POST['univgraddate']) . "</td></tr>";
$message .= "<tr><td><strong>University Address:</strong> </td><td>" . strip_tags($_POST['univaddress']) . "</td></tr>";
$message .= "<tr><td><strong>University City:</strong> </td><td>" . strip_tags($_POST['univcity']) . "</td></tr>";
$message .= "<tr><td><strong>University State:</strong> </td><td>" . strip_tags($_POST['univstate']) . "</td></tr>";
$message .= "<tr><td><strong>Universtiy Zipcode:</strong> </td><td>" . strip_tags($_POST['univzipcode']) . "</td></tr>";
$message .= "<tr><td><strong>University Country:</strong> </td><td>" . strip_tags($_POST['univcountry']) . "</td></tr>";
$message .= "<tr><td><strong>Steps Taken:</strong> </td><td>" . strip_tags($_POST['usmle']) . "</td></tr>";
$message .= "<tr><td><strong>Rotation Length:</strong> </td><td>" . strip_tags($_POST['rotationlength']) . "</td></tr>";
$message .= "<tr><td><strong>Speciality #1:</strong> </td><td>" . strip_tags($_POST['speciality1']) . "</td></tr>";
$message .= "<tr><td><strong>Speciality #2:</strong> </td><td>" . strip_tags($_POST['speciality2']) . "</td></tr>";
$message .= "<tr><td><strong>Speciality #3:</strong> </td><td>" . strip_tags($_POST['speciality3']) . "</td></tr>";
$message .= "<tr><td><strong>Research:</strong> </td><td>" . strip_tags($_POST['research']) . "</td></tr>";
$message .= "<tr><td><strong>Additional:</strong> </td><td>" . strip_tags($_POST['additional']) . "</td></tr>";
$message .= "<tr><td><strong>Rotation Start Date:</strong> </td><td>" . strip_tags($_POST['startdate']) . "</td></tr>";
$message .= "<tr><td><strong>Does He Need A Free Call:</strong> </td><td>" . strip_tags($_POST['freecall']) . "</td></tr>";
$message .= "<tr><td><strong>How did he find us:</strong> </td><td>" . strip_tags($_POST['howus']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
$to = "newyorkrotations#gmail.com";//<== update the email address
$headers = "From: $email \r\n";
$headers .= "Reply-To: $email \r\n";
//Send the email!
mail($to,$email_subject,$message,$headers);
//done. redirect to thank-you page.
header('Location: index.php');
Just replace the $email_body with $message with some HTML code.
But it executed as text instead.
Any Help is Appreciatede..
You haven't given proper headers check this example
<?php
$to = 'maryjane#email.com';
$subject = 'Marriage Proposal';
$from = 'peterparker#email.com';
// 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";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Hi Jane!</h1>';
$message .= '<p style="color:#080;font-size:18px;">Will you marry me?</p>';
$message .= '</body></html>';
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>
Maybe you should add HTML content type to your $headers
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

PHP form contact, with checkboxs, error 500

Can anybody help me! This php doesn't work in my web, doesn't send email, if i change die(error), the page say to me that..
There is de php action
<?php
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['mail'];
$Title = $_POST ['position/title'];
$company = $_POST ['company'];
$location = $_POST ['location'];
$telephone = $_POST['telephone'];
$services = $_POST['services'];
$string = join(" \r\n ", $services);
$timeframe = $_POST['timeframe'];
$comments = $_POST['comments'];
$learn = $_POST['learn'];
$message = '<html><body>';
$message .= '<img src="http://www.corbisglobal.com/assets/web/img/contact-CG-logo.png" />';
$message .= '<table rules="all" style="border-color: #666; border : 1px;" cellpadding="10">';
$message .= "<tr style='background: #ddd;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Lastname:</strong> </td><td>" . strip_tags($_POST['lastname']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['mail']) . "</td></tr>";
$message .= "<tr><td><strong>Title/Position:</strong> </td><td>" . strip_tags($_POST['position/title']) . "</td></tr>";
$message .= "<tr><td><strong>Company:</strong> </td><td>" . strip_tags($_POST['company']) . "</td></tr>";
$message .= "<tr><td><strong>Location:</strong> </td><td>" . strip_tags($_POST['location']) . "</td></tr>";
$message .= "<tr><td><strong>Services:</strong> </td><td>" . join(" \r\n, ", $services) . "</td></tr>";
$message .= "<tr><td><strong>Timeframe:</strong> </td><td>" . strip_tags($_POST['timeframe']) . "</td></tr>";
$message .= "<tr><td><strong>Learn about Corbis:</strong> </td><td>" . strip_tags($_POST['learn']) . "</td></tr>";
$message .= "<tr><td><strong>Comments:</strong> </td><td>" . strip_tags($_POST['comments']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
$recipient = "recipient#example.com";
$subject = "Contact Form from CorbisGlobal Web";
$mailheader .= "MIME-Version: 1.0\r\n";
$mailheader .= "From: " . strip_tags($_POST['mail']) . "\r\n";
$mailheader .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($recipient, $subject, $message, $mailheader) or die (error);
header("Location: thankyou.php");
exit;
?>
Your error is probably on the middle row:
$subject = "Contact Form from CorbisGlobal Web";
$mailheader .= "MIME-Version: 1.0\r\n";
$mailheader .= "From: " . strip_tags($_POST['mail']) . "\r\n";
You didn't create the variable $mailheader before you're adding more text to it.
Turn error reporting on and you'll have meaningful error messages that will help you solve most of your problems.
Also, you're doing this:
mail($recipient, $subject, $message, $mailheader) or die (error);
or die (error), you probably didn't define the error constant, and there is no variable with this name in the code you have shown us. To check if the mail function has accepted your input, you can do this:
if (mail($recipient, $subject, $message, $mailheader)){
header("Location: thankyou.php");
}
else{
die("Error sending email");
}

Include Variables in PHP mail command

I'm sure I'm wrong about something basic, but can not find where the error is. I will appreciate your help.
I have a php page with a single 4 fields contact form.
I need send the name and email as variable, so i can see it properly when email is received.
IT WORKS - BUT DONT SEND NAME AND EMAIL AS VARIABLE:
All messages arrives as "no-reply#luchodomain.com" and doesnt look professional (and can't do reply from my outlook)
if ($_POST) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "lucho#hotmail.com";
$subject = "Website CONTACT";
$headers = "From: no-reply#luchodomain.com" . "\r\n" ;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr><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>Subject:</strong> </td><td>" . strip_tags($_POST['subject']) . "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . strip_tags($_POST['message']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
mail($to,$subject,$message,$headers);
}
IT DOENST WORKS (but have the format and variables as i need)
I would like receive the messages like is normal Name, so i can do a quick reply. -This code don't send email, doesn't work-
if ($_POST) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "lucho#hotmail.com";
$subject = "Website CONTACT";
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr><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>Subject:</strong> </td><td>" . strip_tags($_POST['subject']) . "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . strip_tags($_POST['message']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
mail($to,$subject,$message,$headers);
}
I will appreciate your help with this "headers" issue!
Thank you.
Make sure that you are receiving data in your post array. Make sure your form action. You have declared $message variable to blank after assigning the post value in it before. That's not a good trick enough. Please check updated code and let me know.
if ($_POST) {
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$subject = strip_tags($_POST['subject']);
$message = strip_tags($_POST['message']);
$to = "lucho#hotmail.com";
$subject = "Website CONTACT";
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//$message = "";
//$message .= '';
$message .= "\r\nName: " . $name . "";
$message .= "Email: " . $email . "\r\n";
$message .= "Subject: " . $subject . "\r\n";
$message .= "Message: " . $message . "";
//$message .= "";
//$message .= "";
mail($to,$subject,$message,$headers);
}
$to = 'pawanvikasitha2001#gmail.com, aravindasamapath87#gmail.com'; $subject = 'NEW ORDER HAS PLACED'; $message = "$name"; mail ($to,$subject,$message);
When you use the double quotes, You can simply add variables to it. Look at the $message

Php mail() is not sending the emails [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
I am using the php mail() function to send mails from my server. It was working fine before but now I am not getting the simple mail. Mail status is TRUE but emails are not being received. I tested it on the other server its working fine there.
Here is my code:
$to = 'myemail#gmail.com';
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone_number = trim($_POST['phone']);
$message = trim($_POST['message']);
$subject = 'Contact Message from - ' . strip_tags($name);
$headers = "From: " . $name . " <" . $email . "> \r\n";
$headers .= "Reply-To: " . strip_tags($email) . "\r\n";
$headers .= "Content-type: text/html \r\n";
$message = '<html><body>';
$message .= '<h1>Hello, </h1>';
$message .= '</body></html>';
$message .= '<html><body>';
$message .= '<table rules="all" style="border-color: #666; border:1px solid;" cellpadding="10">';
$message .= "<tr><td><strong>Name:</strong> </td><td>" . $name . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . $email . "</td></tr>";
$message .= "<tr><td><strong>Phone Number:</strong> </td><td>" . $phone_number . "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . $message . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
$confirmation = mail($to, $subject, $message, $headers);
if ($confirmation) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.php\">";
} else {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
}
At first check a simple mail.
<?php
ini_set('display_errors',1);
$email = '';//<--your mail
if (mail($email, 'test', 'test') {
echo 'send';
} else {
echo 'problems';
}
Run it. Check your email, if do not send - see errors on display.
Check server's SMTP setting may be its incorrect,
alternative you can use this simple SMPT send mail script.

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