some emails are coming up blank in my inbox. I think the reason may be here in the source code.
The left image is the one that presents the error.
Code:
define( 'OWNER_EMAIL', 'leads#consorciomenegalli.com.br' );
define( 'DONOTREPLY_EMAIL', 'do-not-reply#consorciomenegalli.com.br' );
define( 'OWNER_NAME', 'Menegalli' );
case 'quote-form':
# put the email title here
$title = 'Nova simulação via website';
# email headers
$headers = "MIME-Version: 1.0\n".
"Content-type: text/html; charset=utf-8\n".
"Content-Transfer-Encoding: 8bit\n".
"From: ". $_POST['clientName'] ." <". $_POST['clientEmail'] .">\n".
"Reply-to: ". $_POST['clientName'] ." <". $_POST['clientEmail'] .">\n".
"Date: ". date( "r" ). "\n";
# appointment values
$values = $_POST['values'];
# create rows with values from appointment form
$rows = '';
for( $i = 0; $i < count( $values ); $i++ ) {
$rows .= '<tr>
<td style="width: 200px; font-weight: bold; border: 1px solid #eee; padding: 10px;">'. $values[$i]['name'] .'</td>
<td style="border: 1px solid #eee; padding: 10px;">'. $values[$i]['value'] .'</td>
</tr>';
}
# email content
$content = '<table style="width: 600px; font-size: 11px; border-collapse: collapse;">'. $rows .'</table>';
# sending an email
$result = mail(
OWNER_EMAIL,
"=?UTF-8?B?". base64_encode( $title ) ."?=",
$content,
$headers
);
# if the email wasn't send
if( $result == false ) {
# second version of email
mail(
OWNER_EMAIL,
"=?UTF-8?B?". base64_encode( EMAIL_TITLE ) ."?=",
$content
);
}
break;
I think the email is not picking up . $values[$i]['name'] . and . $values[$i]['value'] .
Related
I'm trying to send custom email to the user who's purchasing product from our site, I have implemented this code, its working fine but I'm not getting product name and quantity of ordered products. Can anyone help me out and check if Iam missing something in a code or any issues from my end? Thanks
P.s: I'm looking forward to the suggestions from my fellow developers. Thanks
function create_email_body($order_id){
global $woocommerce;
if ( !$order_id )
return;
$order = new WC_Order( $order_id );
$body = '';
$product_list = '';
$order_item = $order->get_items();
foreach( $order_item as $product ) {
$body .= $product['name'];
}
$order = new WC_Order( $order_id );
$body =' <div style = "width: 100%; clear: both; color: #000;">';
$body .=' </div>';
$body .=' <h4> Your order details</h4>';
$body .=' <div style="width: 100%;" id="custom_order_details">';
$body .=' <p> Order Number:<b> '. $order->get_order_number() .'</b> </p>';
$body .=' </div>';
$body .=' <div style="width: 100%;">';
$body .=' <p> Order Date:<b> '. $order->order_date . '</b> </p>';
$body .=' <p> Total Amount:<b>' . $order->get_formatted_order_total(). '</p>';
$body .=' <p> Email: <b><span style = "color: #000 !important"> '. $order->billing_email . '</b> </span></p> ';
$body .=' <p> Payment method: <b> '. $order->payment_method_title .'</p>';
$body .=' <p> Your Phone Number:<b> '. $order->billing_phone .'</b> </p> ';
$body .=' </div>';
$body .=' </div>';
$body .=' <div style = "width: 100%; clear: both; color: #000; margin-top: 30px;">';
$body .=' <table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: "Myriad", sans-serif;" border="1">';
$body .=' <thead>';
$body .=' <tr>';
$body .=' <th class="td" scope="col" style="text-align:left;" style = "; color: #000; background-red;">Produkt</th>';
$body .=' </tr>';
$body .=' </thead>';
$body .=' <tbody>';
$items = $order->get_items();
foreach ( $items as $item_id => $item ) :
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$item_meta = new WC_Order_Item_Meta( $item, $_product );
if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
$body .=' <tr class=' . esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ) .'">';
$body .=' <td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; word-wrap:break-word; color: #000;">';
$body .=' </td><td style = "border: none; color: #000">';
Product name
$body .=$item['name'];' <p style = "display: inline-block; float: left">' . apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
if ( ! empty( $item_meta->meta ) ) {
$body .= nl2br( $item_meta->display( true, true, '_', " " ) );
}
$body .= "</p>";
$body .= '</td>';
$body .=' <td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; color: #000">' . apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item ) .'</td>';
$body .=' <td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; color: #000">' . $_product->get_price();
$body .=' </td>';
$body .=' <td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; color: #000">' . $order->get_formatted_line_subtotal( $item );
$body .=' </td></tr>';
}
endforeach;
$body .=' </tbody>';
$body .=' <tfoot><td style = "border: none;"></td><td style = "border: none;"></td><td style = "border: none; color: #000;"></td>';
$body .=' </tfoot>';
$body .=' </table>';
$body .=' </div>';
$body .= file_get_contents(get_stylesheet_directory_uri() . '/woocommerce/emails/customer-on-hold.order.php');
return $body;
}
function send_email_also_to_customer($order_id){
$order = new WC_Order( $order_id );
$to_email = $order->billing_email;
$headers = 'Od: djohn#dispostable.com <djohn#dispostable.com>' . "
";
$mailer = WC()->mailer();
$subject = 'Confirmation of order receipt number # ' . $order_id;
$body = create_email_body($order_id);
$mailer->send( $to_email, $subject, $mailer->wrap_message( $subject, $body), '', '' );
}
add_action( 'woocommerce_new_order', 'send_email_also_to_customer');
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 have a problem and it sounds stupid, but I'm really stucked.
I need to send "new order" email also to customer. I tried adding function to functions.php file, and it sends email, but doesn't show most of variables. I inserted the same code into sample php file, added as page in wordpress and it works really well. I really don't know what is going on.
Any solutions? Maybe there is more simple way, like adding recipent to "new order"email in woocommerce? I checked class-wc-email-new-order.php file, but I was not able to change anything in there, I don't understand how it works.
screen: code working on page VS what is visible in received email
function create_email_body($order_id){
global $woocommerce;
if ( !$order_id )
return;
$order = new WC_Order( $order_id );
$body = '';
$product_list = '';
$order_item = $order->get_items();
foreach( $order_item as $product ) {
$body .= $product['name'];
}
$order = new WC_Order( $order_id );
$body =' <div style = "width: 100%; clear: both; color: #000;">';
$body .=' <div style="width: 50%; float: left;">';
$body .=' <p> Numer zamówienia:<b> '. $order->get_order_number() .'</b> </p>';
$body .=' <p> Imię i nazwisko:<b> '. $order->billing_first_name . " " . $order->billing_last_name . '</b> </p>';
$body .=' <p> Sposób dostawy: <b> '. $order->get_shipping_method() .'</b> </p>';
$body .=' <p> Status zamówienia:<b> przyjęte</b> </p>';
$body .=' <p> Adres dostawy: <b> '. $order->shipping_address_1 . " " . $order->shipping_address_2 . ", " . $order->shipping_postcode . " " . $order->shipping_city . ", " . $order->shipping_state . $order->shipping_country .'</b> </p>';
$body .=' </div>';
$body .=' <div style="width: 50%; float: left;">';
$body .=' <p> Data zamówienia:<b> '. $order->order_date . '</b> </p>';
$body .=' <p> Email: <b><span style = "color: #000 !important"> '. $order->billing_email . '</b> </span></p> ';
$body .=' <p> Metoda płatności: <b> '. $order->payment_method_title .'</p>';
$body .=' <p> Numer telefonu:<b> '. $order->billing_phone .'</b> </p> ';
$body .=' </div>';
$body .=' </div>';
$body .=' <div style = "width: 100%; clear: both; color: #000; margin-top: 30px;">';
$body .=' <table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: "Myriad", sans-serif;" border="1">';
$body .=' <thead>';
$body .=' <tr>';
$body .=' <th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;"></th>';
$body .=' <th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;">Produkt</th>';
$body .=' <th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;">Ilość</th>';
$body .=' <th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;">Cena</th>';
$body .=' <th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;">Wartość</th>';
$body .=' </tr>';
$body .=' </thead>';
$body .=' <tbody>';
$items = $order->get_items();
foreach ( $items as $item_id => $item ) :
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$item_meta = new WC_Order_Item_Meta( $item, $_product );
if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
$body .=' <tr class=' . esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ) .'">';
$body .=' <td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; word-wrap:break-word; color: #000;">';
$body .=' </td><td style = "border: none; color: #000">';
// Product name
$body .=$item['name'];///' <p style = "display: inline-block; float: left">' . apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
if ( ! empty( $item_meta->meta ) ) {
$body .= nl2br( $item_meta->display( true, true, '_', "\n" ) );
}
$body .= "</p>";
$body .= '</td>';
$body .=' <td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; color: #000">' . apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item ) .'</td>';
$body .=' <td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; color: #000">' . $_product->get_price();
$body .=' </td>';
$body .=' <td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; color: #000">' . $order->get_formatted_line_subtotal( $item );
$body .=' </td></tr>';
}
endforeach;
$body .=' </tbody>';
$body .=' <tfoot><td style = "border: none;"></td><td style = "border: none;"></td><td style = "border: none; color: #000;"></td>';
$body .=' <td style = "border: none; color: #000;">';
$body .=' <p> Wartość produktów </p> ';
$body .=' <p> Cena wysyłki </p>';
$body .=' <p> Do zapłaty </p>';
$body .=' </td>';
$body .=' <td style = "border: none; color: #000;">';
$body .=' <p>' . number_format((float)$order->get_subtotal(), 2, '.', '') . " zł" . '</p>';
$body .=' <p>' . number_format((float)$order->get_total_shipping(), 2, '.', '') . " zł" . '</p>';
$body .=' <p>' . $order->get_formatted_order_total(). '</p>';
$body .=' </td>';
$body .=' </tfoot>';
$body .=' </table>';
$body .=' </div>';
$body .= file_get_contents(get_stylesheet_directory_uri() . '/woocommerce/emails/customer-on-hold.order.php');
return $body;
}
function send_email_also_to_customer($order_id){
$order = new WC_Order( $order_id );
$to_email = $order->billing_email;
$headers = 'Od: AB.com <a#b.com>' . "\r\n";
$mailer = WC()->mailer();
$subject = 'Potwierdzenie przyjęcia zamówienia numer # ' . $order_id;
$body = create_email_body($order_id);
$mailer->send( $to_email, $subject, $mailer->wrap_message( $subject, $body), '', '' );
}
add_action( 'woocommerce_new_order', 'send_email_also_to_customer');
You do not need to do all these stuff again for sending multiple emails. You can simply add recipient to "New Order" email(with customer's email). Here is the code you can try:
<?php
/**
* Add another email recipient for admin New Order emails if a shippable product is ordered
*
* #param string $recipient a comma-separated string of email recipients (will turn into an array after this filter!)
* #param \WC_Order $order the order object for which the email is sent
* #return string $recipient the updated list of email recipients
*/
function sv_conditional_email_recipient( $recipient, $order ) {
// Bail on WC settings pages since the order object isn't yet set yet
// Not sure why this is even a thing, but shikata ga nai
$page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : '';
if ( 'wc-settings' === $page ) {
return $recipient;
}
// just in case
if ( ! $order instanceof WC_Order ) {
return $recipient;
}
$items = $order->get_items();
// check if a shipped product is in the order
foreach ( $items as $item ) {
$product = $order->get_product_from_item( $item );
// add our extra recipient if there's a shipped product - commas needed!
// we can bail if we've found one, no need to add the recipient more than once
if ( $product && $product->needs_shipping() ) {
$recipient .= ', warehouse-manager#example.com';
return $recipient;
}
}
return $recipient;
}
add_filter( 'woocommerce_email_recipient_new_order', 'sv_conditional_email_recipient', 10, 2 );
WRONG :
$recipient .= ', ' . $order->billing_email
CORRECT:
$recipient .= "," . $order->get_billing_email();
I tested and debug this for a whole day.
Update 2018-2019 - For Woocommerce 3+
The accepted answer code is outdated since Woocommerce 3, with some errors in the code.
get_product_from_item() method is deprecated and replaced by $item->get_product().
The Customer email is missing
There is unnecessary code (removed and replaced).
Here is a similar up to date and clean version:
add_filter( 'woocommerce_email_recipient_new_order', 'custom_new_order_email_recipient', 10, 2 );
function custom_new_order_email_recipient( $recipient, $order ) {
// Avoiding backend displayed error in Woocommerce email settings for undefined $order
if ( ! is_a( $order, 'WC_Order' ) )
return $recipient;
// Check order items for a shipped product is in the order
foreach ( $order->get_items() as $item ) {
$product = $item->get_product(); // Get WC_Product instance Object
// When a product needs shipping we add the customer email to email recipients
if ( $product->needs_shipping() ) {
return $recipient . ',' . $order->get_billing_email();
}
}
return $recipient;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
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;
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=.