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=.
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");
I'm using this plugin: https://es.wordpress.org/plugins/pepro-bacs-receipt-upload-for-woocommerce/ and I want to send a email to the admin after a buyer upload a receipt. I have this code, but it's not sending emails, what am I doing wrong?
add_action( "woocommerce_customer_uploaded_receipt", "send_mail_after_bacs_receipt_uploaded", 10, 2);
function send_mail_after_bacs_receipt_uploaded($OrderID, $UploadedAttachmentID)
{
global $Pepro_Upload_Receipt;
$_image_url = wp_get_attachment_url($UploadedAttachmentID);
$_image_src = wp_get_attachment_image_src($UploadedAttachmentID, 'full');
$_image_src = $_image_src ? $_image_src[0] : $Pepro_Upload_Receipt->defaultImg;
$blog_name = get_bloginfo('name', 'display');
$blog_address = parse_url(get_bloginfo('url'), PHP_URL_HOST);
$blog_mail = "wordpress#$blog_address";
$admin_mail = get_option('admin_email');
$order = new WC_Order($OrderID);
$user_id = $order->get_user_id();
$current_user = get_user_by("ID", $user_id);
$mail_receiver = $current_user->user_email;
$mail_subject = "[$blog_name] BACS Receipt";
$mail_wrapper_styles = "display:block;
width:450px;
border-radius:0.5rem;
margin: 1rem auto;
text-align: center;
color: #2b2b2b;
padding: 1rem;
box-shadow: 0 2px 5px 1px #0003;
border: 1px solid #ccc;";
$mail_body = "<div style='$mail_wrapper_styles'>";
$mail_body .= "<h2>BACS Payment Proof Received</h2>";
$mail_body .= "<p>Hello <strong>$current_user->display_name</strong>, We've received you BACS Payment Proof.</p>";
$mail_body .= "<p>We are cheking nearly thousand payments daily and yours is in the list too.</p>";
$mail_body .= "<p>Please be patient, thank you.</p><br />";
$mail_body .= "<a href='$_image_url' target='_blank'>";
$mail_body .= " <img title='Click to enlarge' style='border-radius: 0.5rem;' src='$_image_src' width='400px' />";
$mail_body .= "</a><br />";
$mail_body .= "<p><strong><small>Copyright © $blog_name ($blog_address), all rights reserved.</small></strong><br />";
$mail_body .= "<small style='color: #717171;'>THIS MAIL WAS SENT TO <i>$mail_receiver</i></small></p>";
$mail_body .= "</div>";
$headers = array(
"Content-Type: text/html; charset=UTF-8",
"From: $blog_name <$blog_mail>"
);
// https://developer.wordpress.org/reference/functions/wp_mail/
wp_mail( $mail_receiver, $mail_subject, $mail_body, $headers );
}
I'm trying to insert a button in an anchor tag with an href. I want the user to see a button and not a link
<a href='http://example.com/PhpProject3/reset_passwd.php?key="<?= $email; ?>"&userid="<?= $userid; ?>"' style=' background-color: #4CAF50;border: none;color: white;padding: 15px 32px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;'>Click To Reset password</a>
You can use HTML in your mail like this :
<?php
$to = "somebody#example.com, somebodyelse#example.com";
$subject = "HTML email";
$message = "<a href='http://example.com/PhpProject3/reset_passwd.php?key=".$email."&userid=".$userid."' style=' background-color: #4CAF50;border: none;color: white;padding: 15px 32px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;'>Click To Reset password</a>";
$message .= "Other Information ";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
Please try this:
$html .= '<tr><td>Reject</td></tr>';
Try this
<a href='http://example.com/PhpProject3/reset_passwd.php?key=".$email."&userid=".$userid."' style=' background-color: #4CAF50;border: none;color: white;padding: 15px 32px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;'>
<button>Click To Reset password</button>
</a>";
Following is my php code for email function which is not sending email and i am not getting where the mistake is. Form data is posting properly but mail is not going.
$imgSrc = "logo1.png";
$bg = "background.jpg";
$subjectPara1 = "Dear admin";
$subjectPara2 = $_POST["message"];
$subjectPara4 = $_POST["email"];
$subject = $_POST["subject"];
$subjectPara3 = $_POST["author"];
$message = '<!DOCTYPE HTML><html>'.
'<head>'.
'<title>Email notification</title>'.
'</head>'.
'<body style="background-image: url('.$bg.');background-size: cover;">'.
'<div id="header" style="width: 80%;height: 60px;margin: 0 auto;padding: 10px;color: #fff;text-align: left;font-family: Open Sans,Arial,sans-serif;">'.
'<img height="50" width="220" style="border-width:0" src="'.$imgSrc.'" >'.
'</div>'.
'<div id="outer" style="width: 80%;margin: 0 auto;margin-top: 10px;">'.
'<div id="inner" style="width: 78%;font-family: inherit;font-size: 15px;font-weight: normal;line-height: 1.4em;color: #fff;margin-top: 10px;">'.
'<p>'.$subjectPara1.'</p>'.
'<p>'.$subjectPara2.'</p>'.
'<p><br/>Regards,<br/>'.$subjectPara3.'</p>'.
'<p>'.$subjectPara4.'</p>'.
'</div>'.
'</div>'.
'<div id="footer" style="width: 80%;height: 40px;text-align: center; padding: 10px; font-family: inherit; font-size: 15px; color: #fff;">'.
'All rights reserved # 2016'.
'</div>'.
'</body></html>';
$to = 'test#exmple.com';
$from = $subjectPara4;
$headers = 'From: test#exmple.com\r\n';
$headers .= 'Reply-To: test#exmple.com\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))
{
echo "<script>window.location='index.php';</script>";
}
Kindly help me to resolve this.
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.