Jump to content

API:Send Email


tcvdveer

Recommended Posts

I use following code to send an e-mail from a custom page in case a creditcard transaction fails. With this example I try to send the e-mail to the client with client id 1.

 

The response result gives a success, but no e-mail is being send. Can anyone point me to what I'm doing wrong here?

 

<?php
include("dbconnect.php");
include("includes/functions.php");
include("includes/clientfunctions.php");

$username = "admin"; 
$password = "xxxxxx";

$url = "http://www.xxxxx.xxx/clients/includes/api.php"; # URL to WHMCS API file

$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "sendemail";
$postfields["messagename"] = "Credit Card Payment Failed";
$postfields["id"] = "1";


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);

?>

Link to comment
Share on other sites

  • 1 year later...
  • 4 weeks later...

I developed a script that send email to customers.

 

<?php
/*
API SendEmail WHMCS
Developed By _Dudu_1533
www.hostcheap.com.br
*/

$mysql_host = 'localhost'; 
$mysql_database = 'whmcs'; 
$mysql_username = 'root'; 
$mysql_password = '1234';  

mysql_connect($mysql_host, $mysql_username, $mysql_password) or die(mysql_error());
mysql_select_db($mysql_database) or die(mysql_error());

$admin['user']     = 'hahahaha'; //Admin Username
$admin['pass']     = '1234'; //Admin Password
$email['template'] = 'Hosting Account Welcome Email';  //Email template
$invoice['id']     = 93; //Invoice ID
$site['api']       = 'http://www.yoursite.com/whmcs/includes/api.php'; //URL API

//Do not change below:
$get_hostingid = mysql_query("SELECT a.id FROM tblhosting a WHERE orderid = (SELECT id FROM tblorders WHERE invoiceid = " . $invoice['id'].")") or die(mysql_error());
$row_hostingid = mysql_fetch_array($get_hostingid);

$strcurl = "username=".$admin['user']."&password=".md5($admin['pass'])."&action=sendemail&messagename=".$email['template']."&id=".$row_hostingid['id'];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $site['api']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $strcurl);
$data = curl_exec($ch);
curl_close($ch);

echo $data;
?>

 

Any doubt, post :)

Link to comment
Share on other sites

  • 2 months later...

I need to send email to custom email address can anyone help me?

 

I developed a script that send email to customers.

 

<?php
/*
API SendEmail WHMCS
Developed By _Dudu_1533
www.hostcheap.com.br
*/

$mysql_host = 'localhost'; 
$mysql_database = 'whmcs'; 
$mysql_username = 'root'; 
$mysql_password = '1234';  

mysql_connect($mysql_host, $mysql_username, $mysql_password) or die(mysql_error());
mysql_select_db($mysql_database) or die(mysql_error());

$admin['user']     = 'hahahaha'; //Admin Username
$admin['pass']     = '1234'; //Admin Password
$email['template'] = 'Hosting Account Welcome Email';  //Email template
$invoice['id']     = 93; //Invoice ID
$site['api']       = 'http://www.yoursite.com/whmcs/includes/api.php'; //URL API

//Do not change below:
$get_hostingid = mysql_query("SELECT a.id FROM tblhosting a WHERE orderid = (SELECT id FROM tblorders WHERE invoiceid = " . $invoice['id'].")") or die(mysql_error());
$row_hostingid = mysql_fetch_array($get_hostingid);

$strcurl = "username=".$admin['user']."&password=".md5($admin['pass'])."&action=sendemail&messagename=".$email['template']."&id=".$row_hostingid['id'];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $site['api']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $strcurl);
$data = curl_exec($ch);
curl_close($ch);

echo $data;
?>

 

Any doubt, post :)

Link to comment
Share on other sites

tx, I know it, but i want send mail from my callback page ( such as payment checker page ) to submitted email address, this email sent from invoice payment form to check page.

 

for example in invoice page my customer want send my bank information to another email address that not registered in my WHMCS, I want create a gateway module to send my bank information by user request to a custom email address that email submitted.

Edited by blackeve
Link to comment
Share on other sites

when email is not stored (think thats not good) you have to send email by self.

 

http://de.php.net/manual/de/function.mail.php ;)

or sending email more savely by using THE email class tool:

http://sourceforge.net/projects/phpmailer/

! you do not need to download this package its just in whmcsroot/includes/class.phpmailer.php

 

just include the package and use like documented:

for example like this -> http://phpmailer.worxware.com/index.php?pg=examplebmail

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