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'];
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 want to check a textarea. If the user enter some links in the textarea, php should automatically tag the links. I'm using this code:
$message = "text with some link within";
$url = '#(?!<a[^>]*?>)(http)?(s)?(://)?(([a-zA-Z])([-\w]+\.)+([^\s\.]+[^\s]*)+[^,.\s])(?![^<]*?</a>)#';
if(preg_match($url, $message) == 1){
$message = preg_replace($url, '$0', $message);
}
The problem is, when there's already a tagged link (with an "a" tag), regex is destroying the link.
Here is an example:
first input from textarea: Hello .... test.com
changed by regex: Hello ... test.com
this is working fine, but if you update this:
Hello ... http://test.com" target="_blank" rel="nofollow" title="test.com" target="_blank" rel="nofollow" title="test.com">test.com">test.com">test.com
Thanks for your help!
I'm not familiar with PHP and maybe this is not a good pattern for url validation, but the point is if there is already an "a" tag, the text is not replaced.
<?php
$message = array(
'Hello ... test.com',
"Hello .... http://www.test.com ..."
);
$url = '#(<a[^>]*>[^<]+</a>|((https?://)?[\w\.-]+\.[a-zA-Z]{2,3}[^\s\W]*))#';
foreach ($message as $msg) {
preg_match($url, $msg, $matches);
if(preg_match($url, $msg) == 1 && count($matches) > 2) {
$msg = preg_replace($url, '$0', $msg);
}
echo $msg.PHP_EOL;
}
// Output:
// Hello ... test.com
// Hello .... http://www.test.com ...
Hope it helps.
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 = $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)
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>