I have a simple php script which I use in form on my website. It works fine, however in a title of a message I receive, I would like to have (next to the "Quote Request") a date taken from the field called "date". I was playing with this code but it didn't work. I know the answer is probably very simple, but I don't know php (yet). How can I do it?
Thank you for any help. The code below.
<?php
$addressto = "email#email.com";
$subject = "Quote Request";
$content = "Name: ".$_POST['name']."\n"
."Date: ".$_POST['date']."\n";
if(!$_POST['name'] || !$_POST['date']){
header("Location: ../quote.html");
exit;
}
$email = $_POST['email'];
if(mail($addressto, $subject, $content, 'From: Contact <'.$email.'>')){
header("Location: ../sent.html");
}
?>
You mean:
$subject = "Quote Request - {$_POST['date']}";
Make sure you're validating the user input so as not to get yourself exploited!
Simple. Change this:
$subject = "Quote Request - " . date("d-m-Y", strtotime($_POST['date']));
Is this what you wanted?
If I understood the question correctly, this should achieve what you need:
<?php
$addressto = "email#email.com";
$subject = "Quote Request ".$_POST['date'];
$content = "Name: ".$_POST['name']."\n"."Date: ".$_POST['date']."\n";
if(!$_POST['name'] || !$_POST['date'])
{
header("Location: ../quote.html");
exit;
}
$email = $_POST['email'];
if(mail($addressto, $subject, $content, 'From: Contact <'.$email.'>'))
{
header("Location: ../sent.html");
}
?>
Try This:
Change
$content = "Name: ".$_POST['name']."\n"
."Date: ".$_POST['date']."\n";
To
$content = "Name: ".$_POST['name']."\n
Date: ".$_POST['date']."\n";
If you want the date to be in the subject with "Quote Request", you could do the following:
$subject = "Quote Request ".$_POST['date'];
Related
Error:
the code:
<?php
$name = $_POST['name'];
$mail = $_POST['mail'];
$message = $_POST['message'];
$to ="bejidev27#gmail.com";
$subject = "New contact from " .$name;
$body = "";
$body .= "Name : " .$name. "\r\n";
$body .= "Email : " .$mail. "\r\n";
$body .= $message. "\r\n";
if($mail !=NULL){
mail($to, $subject, $body);
header("Location: index.html") ;
header("Location: done.html") ;
}
?>
It's not sending the mail nor the page is working i need help ,thanks in advance :D
First, check if your servers are running properly. Then, for the following
$name = $_POST['name'];
$mail = $_POST['mail'];
$message = $_POST['message'];
There need to be values for each you. If you are getting the values from a form, then you have to handle the form first using the 'isset' function, to be able to pass the values to each variables.
I hosted my website on github.My contact form doesn't work.I used PHP and HTML to make it.Here are my php code lines
PHP:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$emailFrom = $_POST['email'];
$mobile = $_POST['number'];
$message = $_POST['message'];
$mailTo = "vukstamenkovic9#zohomail.eu";
$headers = "From: ".$emailFrom;
$txt = "You have received an e-mail from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html?mailsent");
}
?>
When I want to contact,I always get this: 405 Not Allowed
How can I resolve this?I searched it and nothing showed up.I would really appreciate help.
<?php
session_start();
$_SESSION['dnevne'] = $dnevne;
$email_to = "marioznik#gmail.com";
$name = $_POST["name"];
$email_from = $_POST["email"];
$message = $_POST["message"];
$email_subject = "Price is: $dnevne ";
$headers = "From: " . $email_from . "\n";
$headers .= "Reply-To: " . $email_from . "\n";
ini_set("sendmail_from", $email_from);
$sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email_from);
if ($sent)
{
header("Location: http://www.yourdomain.com/thankyou.html");
} else {
echo "There has been an error sending your comments. Please try later.";
}
?>
I add few reccomended things, but still i can't get $dnevne variable to my e-mail. Where is my mistake?
As you define a variable : $dnevna = $nocna + $ukupno on your 1st page, then, I recommand putting this value in a hidden input of the form (so user can't mess with it), then access it through $dnevna = $_POST['dnevna'];
The same thing your are doing with $name = $_POST["name"]; $email_from = $_POST["email"]; $message = $_POST["message"];
Then, you use PHP doc -> mail to make your email formatted as you need, include all needed data, and send it to you...
No need to worry about sessionif you're not using them before...
You need to learn to use sessions. Put session_start(); at the top of each page where you want to use a session variable.
Then add your $xyz variable to it as follows: $_SESSION['xyz'] = $xzy;
Then that variable is accessible anywhere that you're using sessions.
I have a problem with this code returning nothing but a blank page... I have followed several different tutorials to try and get this working, I am not a proficient PHP coder at all - But do have a little understanding. My server however, doesn't show error messages. So pinpointing this is rather hard for me to do!
I added this top section here to prevent spam using a hidden field on the html page that posts to this email page.
<?php
$if(isset($_POST['subject'],$_POST['Customer'],$_POST['Email'],$_POST['Phone'],$_POST['Comment'],$_POST['Product'],$_POST['Amount'],$_POST['Valid'])) {
$if(isset($_POST['Name']) && !empty($_POST['Name'])) {
echo "Spam Detected!";
Die();
}
Here is the email part that is supposed to send email once the above section determines that field "name" is empty.
$subject = $_POST['subject'];
$name = $_POST['Customer'];
$from = $_POST['Email'];
$phone = $_POST['Phone'];
$message = $_POST['Comment'];
$prod = $_POST['Product'];
$cash = $_POST['Amount'];
$valid = $_POST['Valid'];
$to = "email#email.com";
$body = 'HTML EMAIL CONTENT HERE...';
$headers .= "From: $from " . "Subject";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to,$subject,$body,$headers);
}
?>
Any and all help will be greatly appreciated!
Thanks
use this i see your code you use $if try if without $
if(isset($_POST['subject'],$_POST['Customer'],$_POST['Email'],$_POST['Phone'],$_POST['Comment'],$_POST['Product'],$_POST['Amount'],$_POST['Valid'])) {
if(isset($_POST['Name']) && !empty($_POST['Name'])) {
echo "Spam Detected!";
Die();
}
}
I wrote a code using php, html and css. This an contact form that is received by an email after submission. There is no error while submitting but i am not getting the email. I am including the code here. This is the link: http://complaintdesk.byethost15.com/contact.php.
Also I incude the code here.
contact.php
<?php
if(isset($_POST['submit'])){
$name = $_POST['fullname'];
$branch = $_POST['branch'];
$usn = $_POST['usn'];
$sem = $_POST['sem'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$description = $_POST['comment'];
$to = 'email#example.com';
$display = 'From:</br>Name: $name</br>USN: $usn</br>Branch: $branch</br>Semester: $sem</br>Email: $email</br></br>$description';
mail($to,$subject,$display);
echo "<script>alert('Your Complaint has been succesfully submitted, We will contact you soon.')</script>";
};
?>
And the rest of code i am not including...
Try this:
$to_address = "Your email address";
$subject = $_POST['subject'];
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers.= "From: ".$email."\r\n";
if (mail($to_address,$subject,$description,$headers)){
echo "Success";
}
else{
echo "<h2>Unable to submit the form, please recheck the details.</h2>" ;
}
Update: If this does not work then there might be an error with your email configuration. As suggested by other users in the comments above, you might want to look into that part too. This answer is based on assumption that your email server/PHP is configured correctly.