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;
Related
I am getting this warning when the form is submitted without entering any of the fields. The error seems to me from line 35 which uses the implode(). Any help will be really appreciated. Thank you so much for looking.
Thank you so much for looking.
Thank you so much for looking.
Thank you so much for looking.
<?php
$your_email ='email#gmail.com';// <<=== update to your email address
session_start();
$errors = '';
$name = '';
$lastname = '';
$phone = '';
$address = '';
$zipcode = '';
$city = '';
$state = '';
$interested_in = array();
$interested_in = '';
$visitor_email = '';
$user_message = '';
$ansday = '';
$hidansday='';
$qnday=rand(1,7);
$hidansday=$qnday+1;
if($hidansday==8) {$hidansday=1;}
$whatday=jddayofweek ( cal_to_jd(CAL_GREGORIAN, 1,$qnday, 2012) , 1 );
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$zipcode = $_POST['zipcode'];
$city = $_POST['city'];
$state = $_POST['state'];
$interested_in = implode(",", $_POST['interested_in']);
$visitor_email = $_POST['visitor_email'];
$user_message = $_POST['message'];
$hiddenansday= $_POST['hidansday'];
$ansday = $_POST['ansday'];
$dw1=trim(strtolower($ansday));
$dw2=strtolower(trim(jddayofweek (cal_to_jd(CAL_GREGORIAN, 1,$hiddenansday, 2012) , 1 )));
///------------Do Validations-------------
$email = htmlspecialchars($_POST['visitor_email']);
if (!preg_match("/([\w\-]+\#[\w\-]+\.[\w\-]+)/",$visitor_email))
{
$errors .= "\n E-mail address not valid ";
}
if ($dw1!==$dw2)
{
$errors .= "\n Please enter valid day for the Security Question";
}
if(empty($name))
{
$errors .= "\n First Name is a required field. ";
}
if(empty($address))
{
$errors .= "\n Please enter your address. ";
}
if(empty($zipcode))
{
$errors .= "\n Please enter your ZIP Code. ";
}
if(empty($city))
{
$errors .= "\n Please enter your City. ";
}
if(empty($state))
{
$errors .= "\n Please enter your State. ";
}
if( !preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $phone) ) {
$errors .= "\n Please enter a valid phone number ";
}
if(empty($errors))
{
//send the email
$to = $your_email;
$subject="Web Form";
$from = $visitor_email;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$body = "A user $name submitted the contact form:\n".
"First Name: $name\n".
"Last Name: $lastname \n".
"Phone: $phone \n".
"Email: $visitor_email \n".
"Address: $address \n".
"Zip Code: $zipcode \n".
"City: $city \n".
"State: $state \n".
"Interested In (Check all that apply): $interested_in \n".
"Message: \n ".
"$user_message\n".
"IP: $ip\n";
$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to, $subject, $body,$headers);
header('Location: thankyou.php');
}
}
?>
This is the HTML part.
<p>
Service Interested In <small>(Check all that apply):</small> <br/>
<input name="interested_in[]" type="checkbox" id="interested_in1" value="Internet"/> Internet<br>
<input name="interested_in[]" type="checkbox" id="interested_in2" value="Telephone" /> Telephone<br>
<input name="interested_in[]" type="checkbox" id="interested_in3" value="Key System" /> Key Systems<br>
</p>
If you tick at least one of the checkboxes and submit the form , there will be no error/warning because $_POST['interested_in'] will not be empty.
However, if you do not tick any of the checkboxes, then system will prompt warning because now $_POST['interested_in'] is empty but you try to use implode() on it.
Hence, you need to check whether $_POST['interested_in'] has value(s) or not first, say by using isset
So, change the line
$interested_in = implode(",",$_POST['interested_in']);
to
if (isset($_POST['interested_in'])){
$interested_in = implode(",",$_POST['interested_in']);
}
im trying to send mail in php,so that mail receiver receives mail with html table, im receiving mail with table but data is missing in mail.. im recieving variable instead of data from html form.
Name: $name
Email: $email
Phone: $phone
Services: $services
Address: $address
Subject: $subject
Message: $message
The code i write is below
<?php
$name = $email = $address = $phone = $service = $subject = $message ="";
$contactErr = "";
$contactsuccess = "";
if (isset($_POST['submit'])) {
$fm_name = $_POST['name'];
$fm_email = $_POST['email'];
$fm_address = $_POST['address'];
$fm_phone = $_POST['phone'];
$fm_service = $_POST['service'];
$fm_subject = $_POST['subject'];
$fm_message = $_POST['message'];
$name = contact_input($fm_name);
$email = contact_input($fm_email);
$address = contact_input($fm_address);
$phone = contact_input($fm_phone);
$service = contact_input($fm_service);
$subject = contact_input($fm_subject);
$message = contact_input($fm_message);
if (empty($fm_name)) {
$contactErr = "Name is Required.";
}
elseif (empty($fm_email)) {
$contactErr = "Email. is Required.";
}
elseif (!filter_var($fm_email, FILTER_VALIDATE_EMAIL)) {
$contactErr = "Invalid email format";
}
elseif (empty($fm_address)) {
$contactErr = "Enter you address.";
}
elseif (empty($fm_phone)) {
$contactErr = "Phone No. is Required.";
}
elseif (empty($fm_service)) {
$contactErr = "Select your desired service !";
}
elseif (empty($fm_subject)) {
$contactErr = "Subject is Required.";
}
elseif (empty($fm_message)) {
$contactErr = "Enter your message!";
}
else{
$info = '<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<table border="1" cellspacing="3" width="60%">
<tr>
<td>Name:</td>
<td>$name</td>
</tr>
<tr>
<td>Email:</td>
<td>$email</td>
</tr>
<tr>
<td>Address:</td>
<td>$address</td>
</tr>
<tr>
<td>Phone:</td>
<td>$phone</td>
</tr>
<tr>
<td>Subject:</td>
<td>$subject</td>
</tr>
<tr>
<td>Services:</td>
<td>$service</td>
</tr>
<tr>
<td>Message:</td>
<td>$message</td>
</tr>
</table>
</body>
</html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mailto = "satish.innovstudio#gmail.com";
$sub = "Get In Touch With Us";
mail($mailto,$sub,$info,$headers);
$contactsuccess = "Your message has been sent successfully! We will contact you shortly.";
$name = $email = $address = $phone = $service = $subject = $message ="";
}
}
function contact_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
You have all of your variables just written out in the string. You're going to need to concatenate them.
instead of
<td>$message</td>
it should be
<td>.$message.</td>
Just change the ' to " at the start and end of $info variable string declaration (you then need to escape every " character in your string or change it to ') OR change your variables to, for example, '. $name .'.
In single quotes variables are not interpreted as they are in double quoted strings.
Read answer to this question about the difference between single and double quotes in PHP strings to get what you are doing wrong:
https://stackoverflow.com/a/3446286/15182618
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 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 = '';
}
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;