mailjet / mailjet-apiv3-php-simple

[API v3] Simple PHP wrapper for the Mailjet API /!\ [DEPRECATED - SEE README] /!\
https://dev.mailjet.com
MIT License
55 stars 45 forks source link

How to set a from name? #117

Closed godspeed20 closed 9 years ago

godspeed20 commented 9 years ago

All the other api's (and the php wrapper according to the mailjet website) allow you to set the FromName param but it doesn't look like the wrapper supports this? is there any way to get that functionality added at all?

If not, and there's no reason you don't support it, I might try adding it in if I get a chance

ta

godspeed20 commented 9 years ago

similarly with html vs text content for the message body

WeshGuillaume commented 9 years ago

Hi @godspeed20 ! Thank you for using our php wrapper ! :)

Hope this work for you:

$mj = new Mailjet(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$params = array(
    "method" => "POST",
    "FromEmail" => "YOUR EMAIL",
    "FromName" => "Mailjet Pilot",
    "Subject" => "Your email flight plan!",
    "Text-part" => "It worked !",
    "Html-part" => "<h3>It worked !!</h3><br />",
    "Recipients" => array(array("Email" => 'gbadi@mailjet.com'))
);
$result = $mj->send($params);
if ($mj->_response_code == 200){
   echo "success";
   var_dump($result);
} else {
   echo "error - ".$mj->_response_code;
   var_dump($mj->_response);
}

Please let me know ! Best, Guillaume from Mailjet !

godspeed20 commented 9 years ago

weird, if i do that i get

Class Object ( [ErrorInfo] => [ErrorMessage] => Unknown resource: "send" [StatusCode] => 400 )

If I use sendEmail (as per the homepage of this particular git repo) I get

Warning: strpos() expects parameter 1 to be string, array given in D:\xampp\htdocs\iiuk\Library\Mailjet\php-mailjet-v3-simple.class.php on line 113

and a response 400. Which is odd because that's the file attachment code and I dont have one. At present I can only send a message by calling sendEmail with this

$mailParams = array( "method" => "POST", "from" => $fromEmailAddress, "to" => $emailAddress, "subject" => $subject, "text" => $bodyAsText );

If I set "text" to a html body it just shows up in plain text :/

WeshGuillaume commented 9 years ago

Please make sure you either clone the updated master branch or download the last release I just published v1.1.0 :)

godspeed20 commented 9 years ago

Perfect, thank you!