Trying to build contact page. I would like to be able to send multiple emails in one time. email addresses have been pulled in from database. I am managing getting them all with do while. However to add "bcc" all addresses I need them to be in one variable for example $emails. I cannot seem to figure out how to do that. This is what I have so far:
$username = $_POST['Username'];
$email = $_POST['email'];
$to="email goes here";
$from= $_POST['email'];
$subject= "Raiding Team Announcement";
$footer="© Copyright 2015 All Rights Reserved ";
$message .= '<html><body>';
$message .= '<div style="width:100%; background-color:#333;">';
$message .= '<h1 style="font-size:50px; color:#FFCC00; text- align:center; display:block; padding-bottom:15px; border-bottom:1px solid #AA0114; ">HellscreamsFury</h1>';
$message .='<h2 style="font-size:32px;color:#f37e0e; text-align:center;">' .$_POST["Username"].' says:</h2>';
$message .='<div style="margin:30px; padding:10px; border:1px solid #404040; margin-bottom:50px;">';
$message .='<p style="font-size:18px; color:#ccc;">' .$_POST["message"]. '</p>';
$message .= '</div>';
$message .= '<div style="border-top:1px solid #AA0114;">';
$message .='<p style="font-size:12px; color:#fff; text-align:center; padding: 20px 0 50px 0;">' .$footer. '</p>';
$message .= '</div>';
$message .= '</div>';
$message .= '</body></html>';
$headers .= "From: " . $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if(mail($to,$subject,$message,$headers)){
header("Location: ../announcments.php?aid=43");
}
else{
header("Location: ../announcments.php?aid=44");
}
This snippet pulls in my emails:
<?php do { ?>
<?php echo $row_rs_contact_team['email']; ?>
<?php } while ($row_rs_contact_team = mysql_fetch_assoc($rs_contact_team)); ?>
I would need them to sit in one variable - let's say $emails. How do I do that? Also emails are pulled in while checking user_id, but sometimes user_id repeats - is there a way to pull that email in once instead of pulling let's say three times?
Do can do it by iterating it into a while loop and concat it and adding a comma near to it.
$CountingQuery = "SELECT * FROM users";
$ExecutingCountingQuery = $Connection->query($CountingQuery);
$Bcc = ''; // Declaring a Variable
while($row = $ExecutingCountingQuery->fetch_array())
{
$Bcc .=$row['email'].',';
}
echo $Bcc; // Now $Bcc is your expected output
//The output will be something like
//sa#sysaxiom.com,test#sysaxiom.com,demo#sysaxiom.com,admin#sysaxiom.com,
Note :
I don't know what name you use to store the email coloumn. So i used the name email for the email column.
Also I have used * where you can replace it for your need.
Related
I'm using PHP 7.4.30 and I'm totally new to PHP.
$subject ="My subject";
$message = '<html><body>';
$message .= '<div style="text-align: center; width: 100%; background-color: #fff;">';
$message .= '<div class="info"> </div>';
$message .= '<table style="text-align: justify; margin: auto; background-color: #ebebeb; border: 1px solid #e7e7e7; width: 600px;" cellspacing="0" cellpadding="0" bgcolor="#ebebeb" align="center">';
$message .= '<tbody>';
$message .= '<tr style="line-height: 0px;">';
$message .= '<td style="line-height: 0';
$from = "My website<robot#website.com>";
$replyto = "website#website.com";
$headers = 'Content-Type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Reply-To: '. $replyto . "\r\n";
$headers .= 'Bcc: xxx#xxx.com';
$message = str_replace("\n.", "\n..", $message);
mail($to, $subject, $message, $headers);
Looking at the delivery track from the server, I see the error message:
"message has lines too long for transport"
Can anyone help?
I have recently faced this issue. An easy solution to this issue is replacing this line
$message = str_replace("\n.", "\n..", $message);
with
$message = wordwrap($message, 70,"\r\n");
my form structure go to the mail but my values are blank.My database values does not get replaced in quotes.How to write it inside qupte when i am using tag
<?php
$eid = $_SESSION['id1'];
$select= "SELECT email from emp_details where id = '".$eid."' ";
$result= mysql_query($select);
$rows= mysql_fetch_array($result);
$to= $rows['email'];
/
//$a=5;
$subject = "Application form print";
$message = "Warehousing Corporation Employees Welfare Fund Apllication form are as given below.<br>";
$message .= "<br>";
$message .= '<html><body>';
$message .= "<div style= 'border-style: solid; border-width: medium;margin: auto;padding: 10px;width: 1024px;'>
<h2 style='text-align:center;'> Warehousing Corporation Employees Welfare Fund </h2>
<h2 style='text-align:center;'> Application form </h2>
<br>Application Id :<b><?php echo $_SESSION["id1"]; ?></b>";
$message .= "</body></html>";
$message .= "<br>Regards,<br>";
$message .= "Team| Welfare Fund.<br>";
$message .= "Email- welfarefund.mswc#gmail.com | Web- www.welfarefundmswc.com<<br>";
$message .= "Contact – 8408882561<br>";
$headers = "From: welfarefund.mswc#gmail.com" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to,$subject,$message,$headers);
?>
Try this :
$to = $rows[0]['email']; because you are using mysql_fetch_array
and change this because you are using the php session
$message .= "<div style= 'border-style: solid; border-width: medium;margin: auto;padding: 10px;width: 1024px;'>
<h2 style='text-align:center;'> Warehousing Corporation Employees Welfare Fund </h2>
<h2 style='text-align:center;'> Application form </h2>
<br>Application Id :<b>". $_SESSION['id1']."</b>";
I am sending a newsletter using the following code I am going to post. I have a $to variable that is for email addresses in my database. I use a while loop to send an email for each email address in my database to preserve privacy. At the bottom of the email I have a link for unsubscribing which is linked to a simple script that has the users email in the link. The $to variable is not working in the link though. The email sends but when I look to see if it sent all the data the link looks like http://example.com/scripts/php/unsubscribe.php?email= instead of http://example.com/scripts/php/unsubscribe.php?email=example#email.com.
I'm not sure what I've done wrong here since I am getting no errors, and the script is working except for sending the email in the link.
require('/home/jollyrogerpcs/public_html/settings/globalVariables.php');
require('/home/jollyrogerpcs/public_html/settings/mysqli_connect.php');
mysqli_select_db($conn,"newsletterlist");
$query = "SELECT * FROM newsletterusers";
$result = mysqli_query($conn, $query);
$subject = str_ireplace(array("\r", "\n", '%0A', '%0D'), '', $_POST['subject']);
$message = str_ireplace(array("\r", "\n", '%0A', '%0D'), '', $_POST['body']);
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: Jesse Elser<jesse#jollyrogerpcs.com>' . "\r\n";
if (!$result) exit("The query did not succeded");
else {
while ($row = mysqli_fetch_array($result)) {
$to = $row['email'];
$date = date("m/d/Y h:i:sa");
$body ='<!DOCTYPE HTML>';
$body .='<body style="padding: 0; margin: 0; background-color: #000; color: #fff; text-align: center; font-family: verdana;">';
$body .='<div id="container" style="width: 90%; margin: 0 auto; text-align: left; background-color: #121212;">';
$body .='<div id="header" style="border-bottom: 1px solid #ff6400;">';
$body .='<img src="http://jollyrogerpcs.com/images/main/logo.png" width="100%">';
$body .='</div>';
$body .='<div id="subject" style="background-color: #121212; text-align: center;">';
$body .='<h1 style="color: #ff6400; margin: 0;">'.$subject.'</h1>';
$body .='</div>';
$body .='<div id="message" style="background-color: #232323; color: #fff; padding: 10px;">';
$body .= $message;
$body .='</div>';
$body .='<div id="footer" style="background-color: #121212; padding: 10px;">';
$body .='Visit Our Site | Thanks for subscribing to our newsletter! | Unsubscribe <br> E-mail sent: ';
$body .= $date;
$body .='</div>';
$body .='</body>';
mail($to,$subject,$body,$headers);
}
}
mysqli_close($conn);
header('Location: http://jollyrogerpcs.com/newsletter.php');
You are closing the href attribute before the email address is included so...
<a href="http://example.com/scripts/php/unsubscribe.php?email="'.$to.'"
Should be
<a href="http://example.com/scripts/php/unsubscribe.php?email='.$to.'"
As is it would render as
<a href="http://example.com/scripts/php/unsubscribe.php?email=" email#address.com"....
Which would make the link http://example.com/scripts/php/unsubscribe.php?email=.
I am new to php coding and in my project I would like to draw squares around the square-shaped php forms I made.
However, I have difficulties in doing so... As you can see the the code below, I was testing and try to draw a square with a div below but it is not showing... Can someone please suggest what have I done wrong please?
Cheers,
Karen
<?php
$to = 'sender#email.com';
$subject = 'HTML Form in HTML Email';
$headers = "From: receiver#email.com\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\n";
$message = '<html><body>';
$message .='<div style="width:10px; height:10px; border:1px black !important;">';
$message .='</div>';
$message .= '<form action="http://mysite/process.php" method="post" name="emailCrossword" target="_blank">';
$crossword = array();
$crossword = 6;
for ($i=0; $i<=$crossword.length; $i++){
echo
$message .= '<input type="text" style="width: 13px; text-transform:capitalize;" placeholder="text-align:center;" name="commentText" maxlength="1"></input>';
}
$message .= '<br/>';
$message .= '<br/>';
$message .= '<input type="submit" name="crossword" value="Submit your crossword" /> </form>';
$message .= '</body></html>';
mail($to, $subject, $message, $headers);
?>
I'm not sure what you are trying to achieve, but your css shorthand for the border is wrong:
border:1px black !important;
Should be:
border:1px solid black !important;
For a solid line obviously...
How can I make the user stay on the same page if the required fields in the form aren't filled? Any answer would be greatly appreciated.
<?php
header('Location: COMING SOON.html');
$name = $_POST['name'];
$surname = $_POST['last_name'];
$cons = $_POST['cons'];
$password = $_POST['pass'];
$email = $_POST['email'];
$message = $_POST['message'];
$recipient = "pixiedustmed#yahoo.com";
$to = 'pixiedustmed#yahoo.com';
$subject = "Contact Message from: $name $surname - $email";
$headers = "From: $name $surname \r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "CC: avedis#avedis.ga\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<div class="about-center"><h1 style="font-family: Lato-Light; font-size: 2em">You have received a contact message from Your website.</h1></div>';
$message .= '<table rules="all" style="border-color: #666; font-family: Segoe UI; font-size: 16px;" cellpadding="12">';
$message .= "<tr style='background: #eee;'><td><p style='color: #2c3e50; font-weight:bold'>Name: </p> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><p style='color: #2c3e50; font-weight:bold'>Surname: </p> </td><td>" . strip_tags($_POST['last_name']) . "</td></tr>";
$message .= "<tr><td><p style='color: #2c3e50; font-weight:bold'>Email: </p> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr style='background: #71bdf4;'><td><p style='color: #ffffff'>Message: </p> </td><td>" . strip_tags($_POST['message']) . "</td></tr>";
$message .= "<tr style='background: #34495e;'><td><p style='color: #ffffff'>Consultation Info: </p> </td><td style='color: #ffffff'>" . strip_tags($_POST['cons']) . "</td></tr>";
$message .= "<tr><td><p style='color: #2c3e50; font-weight:bold'>Password: </p> </td><td>" . strip_tags($_POST['pass']) . "</td></tr>";
$message .= "</table>";
$message .= '<br><h1 style="font-family: Lato-Light; font-size: 14px; color:#c0392b;">Click here to open avedis.ga</h1>';
$message .= '<h1 style="font-family: Segoe UI; font-size: 13px; color:#eee;">This is an autogenerated message designed by S.G.</h1>';
$message .= '<div class="about-center">-</div>';
$message .= "</body></html>";
mail($recipient, $subject, $message, $headers, $password) or die("Error!");
echo "Thank You!";
?>
So, as you see, I have put header('Location: COMING SOON.html'); which evantually works.
Plus, in my css, I have put a required="" field which didn't let the user click the submit button and displayed a message. But now that I put a header, the PHP disregards everything.
My site can be accessed by clicking here; scroll down to the end of the page and try in the contact form, and. Let me know what you think about the design and all!
if(empty($name) || empty($surname) || empty($cons) || empty($password) || empty($email) || empty($_POST['email']) || empty($message)){
// do something if a field is empty
} else {
// do something if fields are all filled
}
Put this after you declare the variables like $name, $surname, and $cons.
Use some javascript to ensure that the user has filled all the fields, or just include the php inside the index page and if the user has filled all the forms send the mail, otherwise show an error around the unfilled fields.
Example using jQuery: Check all input fields have been filled out with jQuery
You should check and validate the feilds first and if the feilds are correctly submitted, then only u should redirect the user using the header().
ps: what you asked was actually not clear.
Hope it helps thankz!