Jump to content

sendmail api


Recommended Posts

I want to use the sendmail api to send emails to my clients

this is easy but, is it possible to send them from a different email and name? I want to send from my private email and pretend it was me sending it directly to my client.

I better ask before writing the code to send the email

Link to comment
Share on other sites

Yes, it's possible but not via SendEmail API since it doesn't allow you to change the address on the fly. When I was using the old WHMCS v5 I had to find a workaround. As far as I know no changes have been made to SendEmail API therefore my workaround should be still valid.

You have to make the long ride interacting directly with PHPMailer that is placed in vendor folder. You should do something like this:

<?php

require_once( ROOTDIR . '/vendor/phpmailer/phpmailer/PHPMailerAutoload.php');

$mail = new PHPMailer;
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';

/**
 * Here you should retreive all information from WHMCS (recipients, customers, variables...)
 */

try {
  $mail->Host       = 'mailserver.example.com;
  $mail->SMTPAuth   = true;
  $mail->Port       = 99999;
  $mail->Username   = 'yourMailServer-Username';
  $mail->Password   = 'yourMailServer-Password';
  $mail->AddAddress('recipient@example.com', 'Definitely not Jodie Foster');
  $mail->SetFrom('youremail@example.com', 'Definitely not Rambo');
  $mail->Subject = 'You won 1.000.000 $!';
  $mail->MsgHTML('The pen is on the table... <strong>DAMN IT!</strong>');
  $mail->Send();
  //echo "Message Sent</p>\n";
} catch (phpmailerException $e) {
  //echo $e->errorMessage(); //Pretty error from PHPMailer
} catch (Exception $e) {
  //echo $e->getMessage(); //Boring error from anything else!
}

Of course you can use the same approach also inside a foreach in case you need to send emails to multiple clients.

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