How to send HTML email in drupal 6 using drupal_mail? - drupal-6

How to send HTML email in drupal 6 using drupal_mail ? How can I change HTML header to show email contents in HTML.

You can to set the header in hook_mail_alter()
<?php
hook_mail_alter(&$message) {
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
}
?>

i know this may be late, but it may help others. Its better to use drupal_mail and then set the headers in hook_mail instead of hook_mail alter. an example would be like:
/*drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE)
Lets say we call drupal_mail from somewhere in our code*/
$params = array(
'subject' => t('Client Requests Quote'),
'body' => t("Body of the email goes here"),
);
drupal_mail("samplemail", "samplemail_html_mail", "admin#mysite.com", language_default(), $params, "admin#mysite.com");
/*We now setup our mail format, etc in hook mail*/
function hook_mail($key, &$message, $params)
{
case 'samplemail_html_mail':
/*
* Emails with this key will be HTML emails,
* we therefore cannot use drupal default headers, but set our own headers
*/
/*
* $vars required even if not used to get $language in there since t takes in: t($string, $args = array(), $langcode = NULL) */
$message['subject'] = t($params['subject'], $var, $language->language);
/* the email body is here, inside the $message array */
$body = "<html><body>
<h2>HTML Email Sample with Drupal</h2>
<hr /><br /><br />
{$params['body']}
</body></html>";
$message['body'][] = $body;
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
break;
}
If this is unclear to you, a complete tutorial on this can be found on My Blog
Hope this helps
JK

Related

Why won't custom WordPress page load get_posts array data?

I've got 3 separate files.
Forms (a basic wordpress page built within Wordpress). The data here shows up fine and works as expected.
<div class="select-wrapper">
<select class="paybill" name="provider-name" id="provider-name" onchange="formFilter(this.value)">
<option value="" disabled selected hidden>- Choose a Provider -</option>
<?php foreach( $providerslist as $providerlist ) {
$theprovidernname = get_the_title($providerlist);
$providerlocations = get_field('provider_locations', $providerlist);
$pcount = count($providerlocations);
for($i = 0; $i < $pcount; $i++){
$location_name = get_field_object('location_name', $providerlocations[$i]);
if(!empty($location_name)){
break;
}
}
if(empty($location_name)){
$location_name = array(value=>"TEXT");
}?>
<option value="<?php echo $location_name['value']?>"><?php echo $theprovidernname; ?></option>
<?php } ?>
</select>
</div>
A filtering Javascript file. The purpose of this file is to get the data from the select field and pass it using AJAX to the 3rd PHP file.
function formFilter(str){
//clears previous results
document.getElementById("form-results").innerHTML = "";
var value = str.value;
console.log(value);
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
document.getElementById("form-results").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET",".../framework-forms-results.php?location="+value,true);
xmlhttp.send();
}
A custom PHP file living in the Child Theme folder of the site. What I'm trying to do is call a custom post type called 'location' and then work through the data. On other pages I'm able to get this exact code to work just fine but here it will not work at all. This is the entirety of this Page at the moment. If I remove the get_posts code and just echo some text, it will return the text so I know the issue is with the get_posts call. I just can't figure out why. If I try to load this page alone without going through the select options, it still returns a 500 error.
//Create Array of All Locations
$locations = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'location',
));
print "<pre>";
print_r($locations);
print "</pre>";
Any thoughts as to why the get_posts call won't work on this custom page but will work if it's used via shortcodes on pages built within wordpress?
I've tried debugging, logging errors and reviewing the logs. I've tried to require the blog header to bring in other necessary files but nothing.
If you are calling this URL directly, which is not how WordPress ajax is intended to work, you can still get this code to run by adding this PHP code:
$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
require_once( $parse_uri[0] . 'wp-load.php' ); to the top of the file.
Link: https://codex.wordpress.org/AJAX_in_Plugins (I know this says Ajax in plugins but this is also what you would do if developing a custom theme to keep your code WordPress-y).

select option from Bot response

I am new to API.ai. I want to functionality such that when a Bot response says something to select from various options, user will select one of the options.
e.g.,
If Bot response says 'Which type of websites do you want to build?'
Select one of the given options.
1) Static
2) Dynamic
3) One page.
I have gone though various helps from the documentation , but I do not know how to set this up.
Please help.
This is your answer :
$arr = [];
if ($var == "Which type of websites do you want to build?") {
$arr[] = "Static";
$arr[] = "Dynamic";
$arr[] = "One page";
} else {
$arr[] = "option1";
$arr[] = "option1";
$arr[] = "option1";
}
Html Code:
<select name="website">
<?php
foreach ($arr as $key => $value) {
?>
<option value="<?php echo $value ?>"><?php echo $value; ?></option>
<?php
}
?>
</select>
Let me know if you require more details.

change font size for phpmailer subject

The following function works but I am unable to control the font-size of the "Subject". Is there a way to change the font size of the "Subject". I've tried:
$mail->Subject = "<span style='font-size:3vw'>" .$mailInputs['subject'] ."<\span>";
but that didn't work.
function mailerExpressBlueHost(array $mailInputs){
require_once '../includes/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsMail();
$mail->SetFrom('example#xyz.com');
$mail->IsHTML(true);
$mail->addAddress('abc#example.com');
$mail->AddEmbeddedImage("../public/img/swb.jpg", "swb-image");
$body = '<!DOCTYPE html>
<html><header>
</header>
<body lang=EN-US>
<div style="text-align:center">
<img src="cid:swb-image">' . $mailInputs['body'] ;
$mail->isHTML(true);
$mail->Subject = $mailInputs['subject'] ;
$mail->Body = $body;
if(!$mail->send()) {
return 'Message could not be sent.' . 'Mailer Error: ' . $mail->ErrorInfo;
} else {
return 'Message has been sent';
}
$mail->ClearAddresses();
}
No, you can't do this. The Subject line does not support HTML formatting; it's plain text only - not least because the definition of the Subject email header predates HTML by at least 10 years.
On the upside, you can use unicode, which allows you quite a lot of tricks, but it's highly dependent on the OS and application it's viewed in.

Prevent CakePHP from stripping chars from url passed as param?

I am developing an application using CakePHP 2.6 and having issues with passing a string containing url characters as a parameter through to a controller method.
In my view I have a chunk of code which echoes out a series of table rows containing data and passes through the page id, unit id and the id of the link which can sometimes contain a url.
<?php foreach($linklist as $l) { ?>
<tr id="Link_<?php echo $l['ID']; ?>">
<td><?php echo $l['Title']; ?></td>
<td class="buttontd"><?php echo $this->Form->postlink('Delete', array('action' => 'deletelink', $this->request->params['pass'][0], $results[0]['PageUnitTypeID'], $l['ID']), array('class' => 'button delete')); ?></td>
</tr>
<?php } ?>
When the postlink button passes the information over to the 'deletelink' action in the controller the url looks like this:
http://mydomainname.com/webpages/deletelink/239/7/urlhttp%3A%2F%2Fwww.google.co.uk%2F
Which shows that the url has been passed as the string but then in the action when I try to just var_dump() the third parameter it returns a string of www.google.co.uk and nothing more which is preventing me from doing a substr() call on the parameter to check if the first 3 characters are equal to url or not.
I have tried to wrap the parameter in the postlink call inside serialize() and urlencode() but neither has had the desired effect of returning the full string as
urlhttp%3A%2F%2Fwww.google.co.uk%2F
Does anyone know of a successful way to pass through a parameter like this without losing important characters?
Update 1: Deletelink action
public function deletelink($pid = null, $uid = null, $lid = null) {
$this->autoRender = false;
if (!is_null($pid) && is_numeric($pid) && !is_null($uid) && is_numeric($uid)) {
if (!is_null($lid)) {
if (substr($lid, 0, 3) == 'url') {
echo substr($lid, 0, 3);
} else {
echo substr($lid, 0, 3);
}
} else {
$this->Session->setFlash('It is unknown which link you wish to delete from the webpage', 'flash_message_bar', array('class' => 'error'));
return $this->redirect(array('action' => 'edit', $pid));
}
} else {
$this->Session->setFlash('It is unknown which on which webpage you wish to delete a link', 'flash_message_bar', array('class' => 'error'));
return $this->redirect(array('action' => 'index'));
}
}
CakePHP (or mod_rewrite I would say) is getting confused with the way your URL is formed.
Your safest option is to base64_encode the url parameter in the view, which will result in call similar to:
http://mydomainname.com/webpages/deletelink/239/7/dXJsaHR0cDovL3d3dy5nb29nbGUuY28udWsv
and base64_decode it later in the action, which will transform
dXJsaHR0cDovL3d3dy5nb29nbGUuY28udWsv
into
urlhttp://www.google.co.uk/

drupal 6 -----why theme() can't output

the code i put in the mytheme template.php
function mytheme_theme(){
return array(
'mytheme_example' => 'example',
'argument' => array('myvar' => null),
);
}
the code i put in the node.tpl.php
<?php
$html = "";
$myvar = "hello,world";
$html .= theme('mytheme_example', myvar);
return $html;
?>
the code i put into the example.tpl.php
<div>
here is the <b><?php print myvar; ?></b>being created.
</div>
i have cleared the cache,but on the node article's page, there is no any output about hello world.
ps:which files i can use the hook_theme, template.php, module file. are there any files i can use this hook?
It looks like you have declared your hook_theme correctly in template.php so I do not think this is the issue.
I did spot a syntax issue with your node.tpl.php, should it not be:
<?php
$vars = array('myvar' => 'hello, world');
$html = theme('mytheme_example', $vars);
return $html;
?>
Note the associate array, with the 'myvar' (the variable declared in hook_theme), is being passed in as the key.
Another point, it is standard practice to name the template file the same as the hook name, so I would suggest calling the template mytheme-example.tpl.php.
See drupal.org for more information
I don't know if you have solved that issue yet.
I would try to declare my theme this way:
function mytheme_theme(){
return array(
'mytheme_example' => array(
'arguments' => array('arguments'=>array()),
'template' => 'example',
),
}
That's how I usually do and it works fine on me.

Resources