Jump to content

sendmail function not working with hook


Waqas Saeed

Recommended Posts

Hello.

Am trying to get the clientID and send the email through 2 LocalAPI method $results1, $results. thus I can see the following results shows on var_dump the $results1, and $results. What I exactly needed ? I need to send the email to the customer whoever redirected to viewinvoice through the param &jazzpending=true. however I do not find any issue with the code but still it doe not work at all. the mail.  the mail should go either the customer has got the product or it's the first sign-up. the purpose of sending the email is to send the full proceddure of payment on their email, and explaining the way to pay through the voucher payment. 

<?php
add_hook('ClientAreaPageViewInvoice', 1, function($vars) {
    $command1 = 'GetInvoice';
$postData1 = array(
    'invoiceid' => $_GET['id'],
);
$adminUsername = 'support@websol.biz'; // Optional for WHMCS 7.2 and later

$results1 = localAPI($command1, $postData1, $adminUsername);
//print_r($results);

$getUserID = (string)$results1['userid'];

$getStatus = $_GET['jazzpending'] == 'true' ? true : false;     
if(isset($_GET['jazzpending']) && $_GET['jazzpending'] == 'true') {
    
$command = 'SendEmail';
$postData = array(
    '//example1' => 'example',
    'messagename' => 'Client Signup Email',
    'id' => $getUserID,
    '//example2' => 'example',
    'customtype' => 'support',
    'customsubject' => 'Product Welcome Email',
    'custommessage' => '<p>Thank you for choosing us</p><p>Your custom is appreciated</p><p>{$custommerge}<br />{$custommerge2}</p>',
    'customvars' => base64_encode(serialize(array("custommerge"=>$populatedvar1, "custommerge2"=>$populatedvar2))),
);
$adminUsername = 'support@websol.biz'; // Optional for WHMCS 7.2 and later

$results = localAPI($command, $postData, $adminUsername);
    
} else {
    
    echo "error";
}
});

var_dump response

array(22) { ["result"]=> string(7) "success" ["invoiceid"]=> int(1962) ["invoicenum"]=> string(0) "" ["userid"]=> int(152) .... !!!

 

Link to comment
Share on other sites

On 07/09/2020 at 14:17, Waqas Saeed said:

Am trying to get the clientID and send the email through 2 LocalAPI method $results1, $results. thus I can see the following results shows on var_dump the $results1, and $results.

that first API call isn't needed - if they're viewing the invoice, they must be logged in (or an admin masquerading as a client)... so there will be a handful of ways to get their clientID. - one of which being to use...

$getUserID = $vars['userid'];

and then if you incorporate that into your hook...

<?php

add_hook('ClientAreaPageViewInvoice', 1, function($vars) {
	
	$getUserID = $vars['userid'];
	if ($_GET['jazzpending'] == 'true') {
		$command = 'SendEmail';
		$postData = array(
			'messagename' => 'Client Signup Email',
			'id' => $getUserID,
			'customtype' => 'general',
			'customsubject' => 'Product Welcome Email',
			'custommessage' => '<p>Thank you for choosing us</p><p>Your custom is appreciated</p><p>{$custommerge}<br />{$custommerge2}</p>',
			'customvars' => base64_encode(serialize(array("custommerge"=>$populatedvar1, "custommerge2"=>$populatedvar2))),
		);
		$results = localAPI($command, $postData);
	}
});

i've changed customtype to general instead of support (as you are working with a clientid) and the two custom mergefields content variables are not being defined, so they'll be blank - though I appreciate you're just copying the example code from the docs.

Link to comment
Share on other sites

15 hours ago, Waqas Saeed said:

Am not looking for too much big CSS or <style> tag but may I know a way to add the css to this ? e.g. adding something h1, p for some good fonts or use theme fonts. 

the email should already use the email template theme as defined in setup -> general settings -> mail (e.g the header, css and footer code) - therefore, your custom message is going to be inside of that and so you should be able to user any CSS that is already defined in there.

for example, if you used...

'custommessage' => '<h1>Thank you for choosing us</h1><h2 style="color:red !important;">Your custom is appreciated</h2><p>{$custommerge}<br />{$custommerge2}</p>',

then it would use the default styling for h1 and overrule the color of h2.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated