Hey, no idea why this sint working, but the message is being sent as "0". I think the e-mail fIELD is what is causing it
<?php
if ($_POST['check'] == 'checked'){
header("location: /nospamplease.html");
exit();
}
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$date = $_POST['date'];
$children = $_POST['children'];
$hot = $_POST['hot'];
$comments = $_POST['comments'];
/*echo $name;
echo $email;
echo $phone;
echo $date;
echo $children;
echo $hot;
echo $comments;*/
if($name == "" || $email == "" || $phone == "" || $date == "" || $children == "" || $hot == "" || $comments == ""){
echo "Please ensure all fields were filled out!";
exit();
}else{
$to = "######";
$subject = "Birthday enquiry";
$message = "Name: ".$name;
$message += "Email: ".$email;
$message += "Phone: ".$phone;
$message += "Date: ".$date;
$message += "Children: ".$children;
$message += "Hot or cold: ".$hot;
$message += "Comments: ".$comments;
//echo $message;
if(mail($to, $subject, $message)){
echo "Thank you for your enquiry, we will contact you within the next 24 hours! <br /> Click <a href='###'> here</a> to go back to the website!";
}else{
echo "There was an error, contact us directly: <a href='mailto:##'>email</a>";
}
}
?>
I echoed out the variables, they all are getting posted fine
Thanks guys
You can't use + to concatenate strings in PHP. Use .
$message .= "Email: ".$email;
Related
Im trying to send an email to 2 variables currently I have tried to add 3 emails to an array and put that into a variable and get the other email from the form, I then dont know how to put both of those variables together when sending so they each have their own "to" but this does not work or something doesnt and I dont know what?? And yes I have real emails that I use these are placeholders for this!!!
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['submit'])) {
$email = $_POST['LOGSE'];
$email2 = array("test#test.com", "test#test.com", "test#test.com");
$name = $_POST['full_name'];
$eventtitle = $_POST['EventT'];
$InCharge = $_POST['InCharge'];
$Venue = $_POST['Venue'];
$VenY = $_POST['VenR'];
if($VenY != "Yes"){
$ava = " Have not checked if";
}
else{
$ava = "";
}
$dates = $_POST['dateS'];
$datee = $_POST['dateE'];
$adults = $_POST['Adults'];
$children = $_POST['Children'];
$catreq = $_POST['CateReq'];
if (catreq != ''){
$catreq = $catreq;
}
else{
$catreq = "No Catering Needed";
}
$logreq = $_POST['LogReq'];
if (logreq != ''){
$logreq = $logreq;
}
else{
$logreq = "No Logistic Equipment Needed";
}
$itreq = $_POST['ITReq'];
if (itreq != ''){
$itreq = $itreq;
}
else{
$itreq = "No IT Needed";
}
$tran = $_POST['TransR'];
if($tran != Yes){
$tran = "NO ";
}
else{
$tran = "";
}
$Risk = $_POST['RiskR'];
if($Risk != Yes){
$Risk = "NO ";
}
else{
$Risk = "";
}
$othern = $_POST['OtherN'];
// The Email:
$from = 'test#test.com';
$to = $email;
$to = $email2;
$subject = 'Event Form ' .$eventtitle;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type:text/html;charset=UTF-8' . "\r\n";
$headers .= 'From: Event Form<test#test.com>' . "\r\n";
$headers .= 'Cc: test#test.com, test#test.com' . "\r\n";
$body = '<html>
<head>
<title>Event</title>
<style>
h1 {
font-family: "Century Gothic", CenturyGothic,
AppleGothic, sans-serif;
}
h3 {
font-family: "Century Gothic", CenturyGothic,
AppleGothic, sans-serif;
}
</style>
</head>
<body>
<h1>Event Details</h1>
<h3>Name: '.$name.'</h3>
<h3>Event Title: '.$eventtitle.'</h3>
<h3>Event Manager: '.$InCharge.'</h3>
<h3>Venue: '.$Venue.' - '.$ava.' Available</h3>
<h3>Date Start: '.$dates.'</h3>
<h3>Date End: '.$datee.'</h3>
<h3>Adults Attending: '.$adults.' Children Attending:
'.$children.'</h3>
<h3>Catering Requirements: '.$catreq.'</h3>
<h3>Logistic Requirements/Equipment: '.$logreq.'</h3>
<h3>IT Requirements: '.$itreq.'</h3>
<h3>Other Notes: '.$othern.'</h3>
<h3><font color="red">'.$tran.'</font>Transport Has Been
Booked</h3>
</body>
</html>' . "\r\n";
mail( $to, $subject, $body ,$headers );
/* echo "An Email Has Been Sent<br>Thank You."; */
header('Location: ./thanks.html');
}
}
The $to in mail function should be a string. If there are more than one email address then those should be comma separated. In your case you might need to do like following.
$to = $email . ','. implode(',', $email2);
Add email address with the comma
$email_to = "test#test.com,some#other.com,yet#another.net";
Also you can add
$headers = "Bcc: someone#domain.com";
Use a foreach on the array:
foreach($email2 as $to){
mail( $to, $subject, $body ,$headers );
}
Or like others are suggesting:
$to = $email.",".implode(",",$email2);
That doesn't make sense:
$to = $email;
$to = $email2;
Parmaeter $to should be a string of comma-seperated email-addresses, e.g.:
$to = $email1 . ", " . $email2 . ", " . $email3;
In my contact form i recently added a selector ( http://shopzuinig.nl/contact.html ) and styled it the way i wanted, but when i fill in the form and press send, the choice for a location is not included in the e-mail i receive. Can someone provide me with the PHP code to make this happen?
Here is my current PHP code:
<?php
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
$replyto='restaurant#dellitalia.nl';
$subject = 'Verzoek via de website';
if($post)
{
function ValidateEmail($email)
{
$regex = "/([a-z0-9_\.\-]+)". # name
"#". # at
"([a-z0-9\.\-]+){2,255}". # domain & possibly subdomains
"\.". # period
"([a-z]+){2,10}/i"; # domain extension
$eregi = preg_replace($regex, '', $email);
return empty($eregi) ? true : false;
}
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$message = stripslashes($_POST['message']);
$phone = stripslashes($_POST['phone']);
$answer = trim($_POST['answer']);
$verificationanswer="6"; // plz change edit your human answer
$from=$email;
$to=$replyto;
$error = '';
$headers= "From: $name <" . $email . "> \n";
$headers.= "Reply-to:" . $email . "\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers = "Content-Type: text/html; charset=utf-8\n".$headers;
// Checks Name Field
if(!$name || !$email || $email && !ValidateEmail($email) || $answer <> $verificationanswer || !$message || strlen($message) < 1)
{
$error .= 'De velden zijn niet correct ingevuld.<br />';
}
if(!$error)
{
$messages.="Name: $name <br>";
$messages.="Email: $email <br>";
$messages.="Message: $message <br>";
$mail = mail($to,$subject,$messages,$headers);
if($mail)
{
echo 'OK';
if($autorespond == "yes")
{
include("autoresponde.php");
}
}
}
else
{
echo '<div class="error">'.$error.'</div>';
}
}
?>
Location Missing in your message. Include location to get location details in your mail.
if(!$error)
{
$mydropdown=$_POST['mydropdown'];
$mydropdown=mysql_real_escape_string($mydropdown);
$messages.="Name: $name <br>";
$messages.="Email: $email <br>";
$messages.="Message: $message <br>";
$messages.="Location: $mydropdown<br>"; // Missing. Include Location Here
$mail = mail($to,$subject,$messages,$headers);
if($mail)
{
echo 'OK';
if($autorespond == "yes")
{
include("autoresponde.php");
}
}
}
I am currently working on a form that needs two post actions with one submit button. I am not extremely versed in PHP, only know enough to make my way around current tasks, until now.
Here is the code for the page the form is on:
<?php
if ($_POST) {
if (empty($_POST['first']) ||
empty($_POST['last']) ||
empty($_POST['email']) ||
empty($_POST['location'])) {
$errors = 1;
} elseif (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errors = 2;
} else {
$to = "emailgoeshere#gmail.com";
$subject = "Blah blah blah";
$message .= "Name: ".$_POST['first']." ".$_POST['last']."\n";
$message .= "Email: ".$_POST['email']."\n";
$message .= "Cell Phone: ".$_POST['cell']."\n";
$message .= "Location: ".$_POST['location']."\n";
$from = $_POST['email'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
header('Location: freepass.php');
exit;
}
}
if ($errors == 1) {
$errors = "Please fill out all fields";
} elseif ($errors == 2) {
$errors = "Please enter a valid email";
}
?>
This is the form action:
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
This is the code on the page that the data will pass to:
<html>
<head>
</head>
<body>
<?php echo $_POST["first"]; ?> <?php echo $_POST["last"]; ?>
<br>
<?php echo $_POST["email"]; ?>
<br>
<?php echo $_POST["cell"]; ?>
<br>
<?php echo $_POST["location"]; ?>
</body>
</html>
This is a very quick solution but it should do the trick.
if ($_POST) {
$errors = null;
$error_message = "<ul>";
if (empty($_POST['first']) ||
empty($_POST['last']) ||
empty($_POST['email']) ||
empty($_POST['location'])) {
$errors = 1;
}
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errors = 2;
}
if($errors == null) {
$to = "grimegriever#gmail.com";
$subject = "City Fitness 7-Day Pass Applicant";
$message .= "Name: ".$_POST['first']." ".$_POST['last']."\n";
$message .= "Email: ".$_POST['email']."\n";
$message .= "Cell Phone: ".$_POST['cell']."\n";
$message .= "Location: ".$_POST['location']."\n";
$from = $_POST['email'];
$headers = "From:" . $from;
mail($to, $subject, $message, $headers);
header('Location: freepass.php');
exit;
} else {
if ($errors == 1) {
$error_message .= "<li>Please fill out all fields</li>";
}
if ($errors == 2) {
$error_message .= "<li>Please enter a valid email</li>";
}
$error_message .= "</ul>";
}
}
I'm sure there are much more efficient solutions, but this will work.
I am having a strange problem with this form. I have made it yesterday night and it was working fine, sending all the emails as it should. However, I've run it today and it won't simply work at all. I am always getting the error message. Any clues? Thank you.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$depart = $_POST['departamento'];
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
$corpo = "Nova Mensagem\n";
$corpo .= "De: " . $name . "\n";
$corpo .= "Email: " . $email . "\n";
$corpo.=" Para o departamento " . $depart. "\n";
$corpo .= "Mensagem: " . $message . "\n";
if ($depart = administrativo)
{
$email_to = '';
}
elseif ($depart = financeiro)
{
$email_to = '';
}
elseif ($depart = Suporte)
{
$email_to = '';
}
else
{
$email_to = '';
}
$status = mail($email_to, $subject, $corpo, $headers);
if($status) {
echo "<script> window.location.href = ''; </script>";
}
else {
echo "<script> window.location.href = ''; </script>";
}
?>
Instead of = use == for comparison
for example - instead of:
if( $depart = administrativo)
use
if( $depart == "administrativo" )
You should enclose strings within quotes. Moreover, == (comparing objects of different types) && === (comparing objects of same types) are used for comparing and = is used for assigning. So, change the code as follows (inside the if statements) :
if ($depart == 'administrativo')
{
$email_to = '';
}
elseif ($depart == 'financeiro')
{
$email_to = '';
}
elseif ($depart == 'Suporte')
{
$email_to = '';
}
else
{
$email_to = '';
}
I can't get the value of the checkbox, the recipient(Administrator or Content Editor), to display it displays "Array" or "A". Also the page redirects automatically without the form first appearing. How do I rectify this?
Here is my code:
contact.php
<?php
$errnam = "";
$errmail = "";
$errsub = "";
$errrec = "";
$hasErrors = false;
if(isset ($_POST['submitted'])){
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$recipient = $_POST['recipient'];
$message = $_POST['message'];
if(preg_match("/^[\w\-'\s]/", $_POST['name'])){
$name = $_POST['name'];
}
else{
$errnam ='<strong>Please enter a name.</strong>';
$hasErrors = true;
}
if (preg_match("/^[\w.-_]+#[\w.-]+[A-Za-z]{2,6}$/i", $email)){
$email = $_POST['email'];
}
else{
$errmail = '<strong>Please enter a valid email.</strong>';
$hasErrors = true;
}
if(preg_match("/^[\w\-'\s]/", $_POST['subject'])){
$subject = $_POST['subject'];
}
else{
$errsub = "<strong>Please enter a subject.</strong>";
$hasErrors = true;
}
if (!empty($_POST['recipient'])) {
for ($i=0; $i < count($_POST['recipient']);$i++) {
$recipient = $_POST['recipient'];
}
}else{
$errrec = "<strong>Please select a recipient</strong>";
$hasErrors = true;
}
$message = $_POST['message'];
}
if ($hasErrors){
echo "<strong>Error! Please fix the errors as stated.</strong>";
}else{
header("Location: form.php?name=".$name."&email=".$email."&subject=".$subject. "&recipient=".$recipient. "&message=".$message);
exit();
}
?>
form.php
<?php
$name = $_GET['name'];
$email = $_GET['email'];
$subject = $_GET['subject'];
$recipient = $_GET['recipient'];
$message = $_GET['message'];
echo "<h2>Thank You</h2>";
echo "<p>Thank you for your submission. Here is a copy of the details that you have sent.</p>";
echo "<strong>Your Name:</strong> ".$name. "<br />";
echo "<strong>Your Email:</strong> ".$email. "<br />";
echo "<strong>Subject:</strong> ".$subject. "<br />";
echo "<strong>Recipient:</strong>" .$recipient. "<br />";
echo "<strong>Message:</strong> <br /> " .$message;
?>
you have the redirection outside the main if statement, just move it inside.
Also you are not accessing the right paramater in the array if you get "Array" back.
for ($i=0; $i < count($_POST['recipient']);$i++) {
$recipient = $_POST['recipient'][$i];
}
you will need to change your function