I have a web site with Muse and I used the contact form widget, it generates a PHP script to send the form with the following function to generate the body message:
function get_email_body($subject, $heading, $fields, $resources) {
$message = '';
$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
$message .= '<html xmlns="http://www.w3.org/1999/xhtml">';
$message .= '<head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><title>' . encode_for_form($subject) . '</title></head>';
$message .= '<body style="background-color: #ffffff; color: #000000; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 18px; font-family: helvetica, arial, verdana, sans-serif;">';
$message .= '<h2 style="background-color: #eeeeee;">' . $heading . '</h2>';
$message .= '<table cellspacing="0" cellpadding="0" width="100%" style="background-color: #ffffff;">';
$sorted_fields = array();
foreach ($fields as $field => $properties) {
// Skip reCAPTCHA from email submission
if ('recaptcha' == $properties['type'])
continue;
array_push($sorted_fields, array('field' => $field, 'properties' => $properties));
}
// sort fields
usort($sorted_fields, 'field_comparer');
foreach ($sorted_fields as $field_wrapper)
$message .= '<tr><td valign="top" style="background-color: #ffffff;"><b>' . encode_for_form($field_wrapper['properties']['label']) . ':</b></td><td>' . get_form_field_value($field_wrapper['field'], $field_wrapper['properties'], $resources, true) . '</td></tr>';
$message .= '</table>';
$message .= '<br/><br/>';
$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">' . sprintf($resources['submitted_from'], encode_for_form($_SERVER['SERVER_NAME'])) . '</div>';
$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">' . sprintf($resources['submitted_by'], encode_for_form($_SERVER['REMOTE_ADDR'])) . '</div>';
$message .= '</body></html>';
return cleanup_message($message);
}
This function makes the host won't send the email message, but if I comment these lines with $_SERVER['SERVER_NAME'] and $_SERVER['REMOTE_ADDR'] the message is sent without problem.
//$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">' . sprintf($resources['submitted_from'], encode_for_form($_SERVER['SERVER_NAME'])) . '</div>';
//$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">' . sprintf($resources['submitted_by'], encode_for_form($_SERVER['REMOTE_ADDR'])) . '</div>';
The script also generate these headers lines:
function get_email_headers($to_email, $form_email) {
$headers = 'From: ' . $to_email . PHP_EOL;
$headers .= 'Reply-To: ' . $form_email . PHP_EOL;
//$headers .= 'X-Mailer: Adobe Muse CC 2015.1.1.343 with PHP' . PHP_EOL;
$headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL;
return $headers;
}
I've really search info about it in Muse forums, etc, but I want to know why these $_SERVER['SERVER_NAME'] and $_SERVER['REMOTE_ADDR'] makes the sent crashes. The host doesn't throws any error or warning message.
Thanks a lot.
Answering the comment:
function cleanup_message($message) {
$message = wordwrap($message, 70, "\r\n");
return $message;
}
function encode_for_form($text) {
$text = stripslashes($text);
return htmlentities($text, ENT_QUOTES, 'UTF-8');// need ENT_QUOTES or webpro.js jQuery.parseJSON fails
}
sprintf($resources['submitted_from'], encode_for_form($_SERVER['SERVER_NAME'])) prints an String like "Sent from the website anubbe.com". It comes from an array.
please dont use any dependency follow this link :- https://github.com/PHPMailer/PHPMailer
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
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 );
}
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.
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 have a working function that I created within my osCommerce page, which sorts products and delivers them to the drop shippers accordingly. It works great, but not on the first page load. In fact its as if the function is never called on until the page is refreshed after it loads up the first time. I really need to get this function to execute on first page load to ensure that these products are emailed to the correct companies. I am calling on the function in checkout_success.php. I have the following just above the tag within the file:
send_dropships_mail($dropship_array, $products_array, $order_id, $deliveryaddress_array);
My function:
function send_dropships_mail($dropship_array, $products_array, $order_id, $deliveryaddress_array) {
// Create new dropships array indexed by dsid
$newDropships = array();
foreach ($dropship_array as $dropship) {
$newDropships[$dropship['id']] = $dropship;
}
// Perform grouping of products by dsid
// Array of 'dsid' => array of product indices
$dstToProduct = array();
foreach ($products_array as $i => $product) {
if (!isset($dstToProduct[$product['dsid']])) {
$dstToProduct[$product['dsid']] = array();
}
$dstToProduct[$product['dsid']][] = $i;
}
$orders_products_id_query = tep_db_query("select orders_products_id from orders_products where orders_id = " . $order_id);
while ($ipidq = tep_db_fetch_array($orders_products_id_query)) {
$orders_products_id_array[] = array('orders_products_id' => $ipidq['orders_products_id']);
}
$orders_products_id_attributes_query = tep_db_query("select orders_products_id, products_options, products_options_values from orders_products_attributes where orders_id = " . $order_id);
while ($opidq = tep_db_fetch_array($orders_products_id_attributes_query)) {
$orders_products_id_attributes_array[] = array('orders_products_id' => $opidq['orders_products_id'],
'p_o' => $opidq['products_options'],
'p_o_v' => $opidq['products_options_values']);
}
$p_attribute = "";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: noreply#email.com \r\n" .
"Reply-To: me#email.com \r\n" .
"X-Mailer: PHP/" . phpversion();
// Now we are ready to send emails
foreach ($dstToProduct as $dsid => $productIndices) {
$email = $newDropships[$dsid]['email'];
$subject = "A new order has been placed";
// Build message text
$date = date('m/d/Y');
$text = '<span style="color: #513311; font-size: 14px;"><table cellpadding="3" style="margin-top: 20px;"><tr style="background-color: #6d7d59; color: #ffffff; font-weight: bold; font-size: 12px;"><td style="width: 240px; vertical-align:text-top;">Product Name</td><td style="width: 120px; vertical-align:text-top;">Model Number</td><td style="width: 80px; vertical-align:text-top;">Quantity</td><td style="width: 80px; vertical-align:text-top;">Price</td></tr>';
foreach ($productIndices as $productIndex) {
$p_attribute = "";
if (count($orders_products_id_attributes_array) > 0) {
foreach ($orders_products_id_attributes_array as $opidaa) {
if ($products_array[$productIndex]['orders_products_id'] == $opidaa['orders_products_id']) {
$p_attribute .= "<i> - " . $opidaa['p_o'] . " " . $opidaa['p_o_v'] . "</i><br>";
} else {
$p_attribute = "";
}
}
}
if ($p_attribute == "") {
$text .= '<tr style="background-color: #f0f0f0; color: #513311; font-size: 12px;"><td style="vertical-align:text-top;">' . $products_array[$productIndex]["text"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["model"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["qty"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["price"] . '</td></tr>';
} else {
$text .= '<tr style="background-color: #f0f0f0; color: #513311; font-size: 12px;"><td>' . $products_array[$productIndex]["text"] . '<br>' . $p_attribute . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["model"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["qty"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["price"] . '</td></tr>';
}
}
$text .= '</table>';
$text .= '<table cellpadding="3" style="margin-top: 20px;"><tr style="background-color: #6d7d59; color: #ffffff; font-weight: bold; font-size: 12px;"><td style="width: 200px;">Delivery Address</td></tr><tr style="background-color: #f0f0f0; color: #513311; font-size: 12px;"><td>' . $deliveryaddress_array[0]['name'] . '<br>' . $deliveryaddress_array[0]['address'] . '<br>' . $deliveryaddress_array[0]['city'] . ', ' . $deliveryaddress_array[0]['state'] . ' ' . $deliveryaddress_array[0]['zip'] . '</td></tr></table>';
if (!mail($email, $subject, $text, $headers)) {
mail('me#email.com', 'Error sending product', 'The follow order was not sent to the drop shippers: ' . $order_id);
}
}
}
Is there a time limit thats set into osCommerce or something? Though that still wouldn't explain why the page needs to be refreshed inorder for the function to work. Any help is appreciated!
You need to place this line and all the logic related to it in header.php at the very top before the initialisation of any other logic.
send_dropships_mail($dropship_array, $products_array, $order_id, $deliveryaddress_array);
The problem is that this function is being called very late in your code which is why all the older values are shown in your rendered HTML and when you refresh your page since the execution had already happened on your last load you see the new data.
Hope it helps ! :)