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
Related
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"] == ""){
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");
}
I am trying on the following code but it keeps saying Mail not sent. How do I find the real issue? Code given below:
$full_name = htmlspecialchars(trim($_POST['full_name']));
$email = htmlspecialchars(trim($_POST['email']));
$phone = htmlspecialchars(trim($_POST['phone']));
$message = htmlspecialchars(trim($_POST['message']));
$to = "mail#example.com";
$subject = $full_name . ' is interested to have a business discussion with you';
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: " . strip_tags($_POST['email']) . "\r\n";
// $headers .= "CC: susan#example.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 .= '<h3>Full Name: </h3>: ' . $full_name . '<br>';
$message .= '<h3>Phone: </h3>: ' . $phone . '<br>';
$message .= '<h3>Message: </h3>: ' . $message . '<br><br>=======================<br>';
$message .= '<h3>IP Address: </h3>: ' . $ip . '<br>';
$message .= '</body></html>';
if(mail($to, $subject, $message, $headers))
{
echo "Mail Sent Successfully";
}else{
echo " Mail Not Sent";
}
Try this code hope this helpful.
<?php
//print_r($_POST);
//$fname = $_POST['fname'];
//$lname = $_POST['lname'];
//$email = $_POST['email'];
//$message = $_POST['message'];
if(isset($_POST['fname']) && $_POST['fname'] != ''){
$fname = $_POST['fname'];
}
if(isset($_POST['lname']) && $_POST['lname'] != ''){
$lname = $_POST['lname'];//phone number
}
if(isset($_POST['email']) && $_POST['email'] != ''){
$email = $_POST['email'];
}
if(isset($_POST['message']) && $_POST['message'] != ''){
$com = $_POST['message'];
}
$to = 'noreply#noreply.com';
$subject = 'Site Visiter.';
// message
$message = sprintf("Site visiter details: <br>Name:- %s <br> Phone:- %s <br> Email:- %s<br> Message:- %s",$fname,$lname,$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";
// Additional headers
$headers .= 'To: Mary <nb158f#gmail.com>' . "\r\n";
$headers .= 'From: mysite.com <admin#site.com>' . "\r\n";
//$headers .= 'Cc: divakar.k#gmail.com' . "\r\n";
// Mail it
$flag = mail($to, $subject, $message, $headers);
echo '<script>alert("Mail Sent :");</script>';
echo '<script>window.location.href="index.php";</script>';
Trying to get my form to email working, but when I add this part of the code
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
the email won't send. When I remove it, the email sends, but all the tags show up. Any idea what the problem is?
My php code is below:
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$injury = $_POST['injury'];
$message = $_POST['message'];
$myemail = 'example#gmail.com';
$subject = 'Brain Damage Info Free Evaluation Form';
$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";
$email_message = '<html><body>';
$email_message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$email_message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$email_message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$email_message .= "<tr><td><strong>Phone:</strong> </td><td>" . strip_tags($_POST['phone']) . "</td></tr>";
$email_message .= "<tr><td><strong>Injury:</strong> </td><td>" . strip_tags($_POST['injury']) . "</td></tr>";
$email_message .= "<tr><td><strong>Description of Injury:</strong> </td><td>" . $_POST['message'] . "</td></tr>";
$email_message .= "</table>";
$email_message .= "</body></html>";
$sent = mail($myemail,$subject,$email_message,$headers);
I use
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
with this i do not get such errors. I think the charset is the problem.
I am sending form data through a .swf file into this PHP page.(see below) When the email is sent, if there is an attachment the body of the message will not appear but if there is not an attachment the body appears just fine. I know that all of the variable names are correct because all of the data has been passed from the swf file. Is there something in the way I have set up the email that makes it work that way? Please let me know.
<?php
$to=$_POST['toEmail'];
$subject=$_POST['subject'];
$body = $_POST['messaggio'];
$nome = $_POST['nome'];
$email = $_POST['email'];
$attach = $_POST['attach'];
$headers = "From: $nome<" . $email . ">\n";
if ($attach == 1) {
$tmp_name = $_FILES['Filedata']['tmp_name'];
$type = $_FILES['Filedata']['type'];
$name = $_FILES['Filedata']['name'];
if(is_uploaded_file($tmp_name)){
$file = fopen($tmp_name,'rb');
$data = fread($file,filesize($tmp_name));
fclose($file);
$data = chunk_split(base64_encode($data));
$headers .= "Reply-To: <" . $email . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDARY_main_message\"\n";
$headers .= "X-Sender: $to <" . $to . ">\n";
$headers .= "Return-Path: <" . $email . ">\n";
$headers .= "This is a multi-part message in MIME format.\n";
$headers .= "------=MIME_BOUNDARY_main_message \n";
$headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDARY_message_parts\"\n";
$message = "------=MIME_BOUNDARY_message_parts\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n";
$message .= "\n";
$message .= $body . "\n";
$message .= "\n";
$message .= "------=MIME_BOUNDARY_message_parts--\n";
$message .= "\n";
$message .= "------=MIME_BOUNDARY_main_message\n";
$message .= "Content-Type: application/octet-stream;\n\tname=\"" . $name . "\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment;\n\tfilename=\"" . $name . "\"\n\n";
$message .= $data;
$message .= "\n";
$message .= "------=MIME_BOUNDARY_main_message--\n";
mail($to, $subject, $message, $headers);
}
} else {
if(mail($to, $subject, $body, $headers)) {
echo "ok=1";
}
}
?>
Building MIME messages, especially with attachments, is painful. You'd be better off using something like PHPMailer, which will handle the whole business for you automatically... You just have to provide the content.
Beyond that, you're slurping the attachments into memory. How big are they? Are you exceeding the script's memory_limit?