I have a big problem! I need to track what the users are doing on my site. As a way to resolve it I crated a sendmail function in order to send me an email every time a user clicks on a button. The code is this:
<div class="buy">
<a onclick="target='_blank'" href="<?php echo $this->product['from'];?>">
<?php
// The message
$message = "A new buy";
$link = $this->product['from'];
// Send
mail('xxx#mail.com', '#buy PRODUCT', $message, $link);
?>
<img src="http://xxx.com/data/images/xxx.jpg" alt="Comprar" />
</a>
</div>
The message I receive is
"A new buy
"
And it should look like:
"A new buy
http://www.xxxx.com"
Anyone can help me with this problem?
You need 2 only pass one message parameter.
$message = $message.$this->product['from'];
mail('xxx#mail.com', '#buy PRODUCT', $message);
mail('xxx#mail.com', '#buy PRODUCT', $message.$link);
try this
mail('xxx#mail.com', '#buy PRODUCT', $message.$link);
Just concatenate any data related to your message to your $message variable and just pass that $message variable into the mail function. For example: $message = $message." Link: ".$link and then mail('xxx#mail.com', $message)
Related
I am using an SMS API to send sms to customer on Thankyou page of woocommerce. The API redirects to the API provide's page after sending the SMS. I asked them for a solution, they suggested to use the iframe. But the redirection exists. Then, they suggested to call variables from page checkout. I am unable to understand. Kindly, guide me. Here, is my code.
function tz_send_message_to_customer($order_id){
$order = new WC_Order( $order_id );
$currency = $order->get_order_currency();
$total = $order->get_total();
$date = $order->order_date;
$name = $order->billing_first_name . $order->billing_last_name;
// Configuration variables
$id = "xxxxx"; // Account Username
$pass = "xxxx"; // Account Password
$mask = "xxxx"; // Account Masking
// Data for text message
$to = $order->billing_phone; // Recipient Number with "92" Pakistan Code
$message = urlencode("Dear " . $name . "!" . "Your following Order is Under Process" . "Order ID: " .$order_id . "Total: " . $currency.$total. "Thankyou For Shopping") ;
// Prepare data for POST request - DO NOT EDIT
$data = "id=".$id."&pass=".$pass."&msg=".$message."&to=".$to."&lang=English"."&mask=".$mask."&type=xml";
// Send the POST request with cURL - DO NOT EDIT
//header("location:http://ip-address/api/sendsms.php?".$data);
$url = "http://ip-address/api/sendsms.php?".$data;
?>
<iframe src="<?php echo $url; ?>"></iframe>
<?php
}
add_action( 'woocommerce_thankyou', 'tz_send_message_to_customer', 10, 1 );
I have found the solution by searching on Google. It was suggested that use sandbox attribute in iframe like sandbox="allow-same-origin". So, the iframe code looks like as
<iframe src="<?php echo $url; ?>" sandbox="allow-same-origin" style=" display: none;"></iframe>
More info can be found at: https://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/
I will really appreciate if you could help me in that coding. I really need help.
I want with single press over the image, to get the data from fields sent over email.
So my HTML image code like that :
<img src="images/some.png" id="help" onClick="help();">
Right before that tag in HTML file I put AJAX like that:
<script type="text/javascript">
function help() {
$.get("/help.php");
return false;
}
</script>
And with that function i want, when the user click over the image to execute my PHP script which is on other file and it contains code like that :
help.php
<?php
{
$helpSubject = 'help';
$webMaster = '****#mail.com';
$helpField = $_POST['help'];
$problemField = $_POST['problem'];
$body = <<<EOD
<br><hr><br>
Help: $help <br>
Problem: $problem <br>
EOD;
$headers = "Reason: $help\r\n";
$headers = "Content-type: text/html\r\n";
$success = mail($webMaster, $helpSubject, $body, $headers);
$theResults = <<<EOD
Success
EOD;
echo "$theResults";
}
?>
Something is wrong, and I can't find what. Could anyone help me with that?
Thank you.
I have a big problem! I need to track what the users are doing on my site. As a way to resolve it I crated a sendmail function in order to send me an email every time a user clicks on a button. The code is this:
<div class="buy">
<a onclick="target='_blank'" href="<?php echo $this->product['from'];?>">
<?php
// The message
$message = "A new buy";
$link = "<?php echo $this->product['from'];?>";
// Send
mail('xxx#mail.com', '#buy PRODUCT', $message, $link);
?>
<img src="http://xxx.com/data/images/xxx.jpg" alt="Comprar" />
</a>
</div>
The message I receive is
"A new buy
**<?php echo $this->product['from'];?>**"
And it should look like:
"A new buy
http://www.xxxx.com"
Anyone can help me with this problem?
Ok, then try this:
$message = "A new buy ".PHP_EOL.PHP_EOL;//add two new lines for plaintext message
$message .= $this->product['from']; //add link to the end of message
// Send
mail('xxx#mail.com', '#buy PRODUCT', $message); //no need for fourth parameter
Read further:
http://php.net/manual/en/function.mail.php
And for easy e-mailing use phpmailer:
http://code.google.com/a/apache-extras.org/p/phpmailer/
Instead of:
$link = "<?php echo $this->product['from'];?>";
use
$link = $this->product['from'];
I am having a strange problem with str_replace in my php code below. What is supposed to happen is on each loop it is supposed to replace {name} with the person's name pulled in from the database. What it is actually doing is if I mail two people, the first one it replaces with thier name, so they get an email dear, bob bla bla bla. The second one always seems to be dear , {name} bla bla bla. It is as though on the second loop, something is failing?
<?php
$formid = mysql_real_escape_string($_GET[token]);
$templatequery = mysql_query("SELECT * FROM hqfjt_chronoforms_data_addmailinglistmessage WHERE cf_id = '$formid'") or die(mysql_error());
$templateData = mysql_fetch_object($templatequery);
$gasoiluserTemplate = $templateData->gasoilusers;
$dervuserTemplate = $templateData->dervusers;
$kerouserTemplate = $templateData->kerousers;
$templateMessage = $templateData->mailinglistgroupmessage;
$templatename = $templateData->mailinglistgroupname;
?>
<?php
require_once('./send/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
// $body = file_get_contents('contents.html');
$body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>#title {padding-left:120px;padding-top:10px;font-family:"Times New Roman", Times, serif; font-size:22px; font-weight:bold; color:#fff;}</style>
</head>
<body>
<div style="background:
none repeat scroll 0% 0% rgb(6, 38,
97); width:780px;">
<img id="_x0000_i1030" style="padding-left:100px;padding-right:100px;"
src="http://www.chandlersoil.com/images/newsletter/header.gif"
alt="Chandlers Oil and Gas"
border="0" height="112"
width="580">
<div id="title">{message}</div>
</div>
</body>
</html>
';
// $body = preg_replace('/\\\\/i', $body);
$mail->SetFrom('crea#cruiseit.co.uk', 'Chandlers Oil & Gas');
$mail->AddReplyTo('crea#cruiseit.co.uk', 'Chandlers Oil & Gas');
$mail->Subject = "Your Fuel Prices From Chandlers Oil & Gas";
$query = "SELECT leadname,businessname,email FROM hqfjt_chronoforms_data_addupdatelead WHERE keromailinglist='$kerouserTemplate' AND dervmailinglist='$dervuserTemplate' AND gasoilmailinglist='$gasoiluserTemplate'";
$result = mysql_query($query);
// Bail out on error
if (!$result)
{
trigger_error("Database error: ".mysql_error()." Query used was: ".htmlentities($query), E_USER_ERROR);
die();
}
while ($row = mysql_fetch_array ($result)) {
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
// THIS PULLS THE CLIENTS FIRST NAME OUT ON EACH LOOP
$firstname = $row["leadname"];
//THIS PULLS THE CLIENTS BUSSINESS NAME OUT ON EACH LOOP
$businessname = $row["businessname"];
// IF THE FIRST NAME FIELD IS BLANK USE THE BUSINESS NAME INSTEAD
if ($firstname = '')
{$name = $row["businessname"];}
else
{$name = $row["leadname"];}
// THIS REPLACES THE {NAME} IN THE PULLED IN TEMPLATE MESSAGE WITH THE CLIENTS NAME DEFINED IN $name
$body = str_replace('{name}', $name, $body);
// THIS REPLACES {fuel} IN THE PULLED IN TEMPLATE WITH THE TEMPLATE NAME (WHICH IS THE TYPE OF FUEL)
$body = str_replace('{fuel}', $templatename, $body);
// THIS REPLACES THE {message} IN THE $body ARRAY WITH THE TEMPLATE MESSAGE HELD IN $templateMessage
$body = str_replace('{message}', $templateMessage, $body);
$mail->MsgHTML($body);
$mail->AddAddress($row["email"], $row["leadname"]);
if(!$mail->Send()) {
echo "Mailer Error (" . str_replace("#", "#", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>';
} else {
echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("#", "#", $row["email"]) . ')<br>';
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
?>
$body contains the mail's template. In your loop, you assign the return value from str_replace() to this variable. After that, you cannot expect it to contain the original template upon a next iteration. You'll have to use a temporary variable for this:
while (...) {
$bodyTemp = str_replace('{name}', $name, $body);
$bodyTemp = str_replace('{fuel}', $templatename, $bodyTemp);
// ...
}
Also, to make your code a little more readable, might I suggest using strtr() instead:
while (...) {
$bodyTemp = strtr($body, array(
'{name}' => $name,
'{fuel}' => $templatename,
// ...
));
}
This saves you the repetitive invocations of str_replace().
Before the loop, $body may contain Dear {name}. Then you loop once, then it contains Dear Iain. Then in the second loop, there is no {name} to replace anymore.
I'm sending HTML mails with swiftmailer. It all works pretty great, my HTML mails are showing up just fine in all clients. I have quite the knowledge of building email templates. Sending them myself not so much...
The problem exists in gmail and hotmail. The image is not showing up. It shows just fine in Thunderbird for instance... gmail is leaving my image blank and adds it as an attachment (at the bottom of the mail, like i'm sending birthday pictures..).
Any ideas?
I've got the following code:
function deliverMail($subject, $data, $from, $to, $template){
if($_SERVER['SERVER_ADDR'] !== '::1'){
if (!is_array($to)){
$to = array($to);
}
$from = explode(",", $from);
//Create the Transport
$transport = Swift_SmtpTransport::newInstance('mail.xxx.nl', 25)
->setUsername('xxx')
->setPassword('xxx');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance($subject);
$image = $message->embed(Swift_Image::fromPath($_SERVER['DOCUMENT_ROOT'].'/templates/emails/xxx.jpg'));
// open the file
$sourcefile = $_SERVER['DOCUMENT_ROOT'].'/templates/emails/'.$template.'.html.tpl';
$fh = fopen($sourcefile, 'r');
$htmltemplate = fread($fh, filesize($sourcefile));
fclose($fh);
// set the content
if($template == 'confirm'){$replaceOld = array("[*code*]", "[*imgsrc*]");}
if($template == 'notify'){$replaceOld = array("[*url*]", "[*imgsrc*]");}
$replaceNew = array($data, $image);
$body = str_replace($replaceOld, $replaceNew, $htmltemplate);
$message->setFrom(array($from[0] => $from[1]))
->setTo($to)
->setBody($body, 'text/html');
if (!$mailer->send($message, $failures)){
return "Failures:";
return print_r($failures);
}else{
return 'success';
}
}
}
Which will render the image in my template here:
<td id="head" height="80" width="640" colspan="3" valign="top" align="left">
<image src="[*imgsrc*]" width="140" height="80" alt="xxx"/>
</td>
I have seen this behaviour in GMail as well and think this is just how GMail displays mail with embedded images.
See this link for more information:http://www.getelastic.com/email-design-for-gmail/
Did you know that Gmail disables
images in HTML emails by default, even
if your customer has added you to his
or her safe list?
Wow, finally settled this. "image" is not a valid HTML tag of course... after trying 3 different php libraries i found this..
<td id="head" height="80" width="640" colspan="3" valign="top" align="left">
<image src="[*imgsrc*]" width="140" height="80" alt="xxx"/>
</td>