Giter Site home page Giter Site logo

Comments (7)

andrebruton avatar andrebruton commented on August 22, 2024 2

Is it not possible for the PHP library code to return an error instead of a fatal error. I do not want fatal errors in a production environment.

I check for returned code and if 200 then i know the email has been delivered to Mailgun.

from mailgun-php.

CupOfTea696 avatar CupOfTea696 commented on August 22, 2024

Go to the RestClient.php file and edit it where the error originated:

        elseif($httpResponseCode == 400){
            die(var_dump((string) $responseObj->getBody()));
            throw new MissingRequiredParameters(EXCEPTION_MISSING_REQUIRED_PARAMETERS);
        }
        elseif($httpResponseCode == 401){
            die(var_dump((string) $responseObj->getBody()));
            throw new InvalidCredentials(EXCEPTION_INVALID_CREDENTIALS);
        }
        elseif($httpResponseCode == 404){
            die(var_dump((string) $responseObj->getBody()));
            throw new MissingEndpoint(EXCEPTION_MISSING_ENDPOINT);
        }

This way you can actually see the response from the request to Mailgun. It might help you figure out what went wrong.
Mailgun should update their package to show this info in the error. I'm gonna make this a bit better looking and create a pull request.

from mailgun-php.

ezyone123 avatar ezyone123 commented on August 22, 2024

Turns out I had not verified my account. Got it figured out, thanks!

from mailgun-php.

CupOfTea696 avatar CupOfTea696 commented on August 22, 2024

You're welcome!

from mailgun-php.

mnpenner avatar mnpenner commented on August 22, 2024

Looks like the error messages were never updated. I just downloaded the SDK and got this cryptic message today. I thought I had to supply the 2nd arg to the c'tor, but that led to a whole new set of problems.

from mailgun-php.

mnpenner avatar mnpenner commented on August 22, 2024

@andrebruton You can always put a try {} catch {} around it.

This error message should still be updated to say "This domain has not been verified yet" or something, if that is indeed the problem.

from mailgun-php.

andrebruton avatar andrebruton commented on August 22, 2024

Thank you. Tried it and I get a message back. Does this look good?

` try {
# Now, compose and send your message.
$result=$mg->sendMessage($domain, array('from' => '[email protected]',
'to' => '[email protected]',
'subject' => $subject,
'text' => $message,
'html' => $message_html
));

if ($result->http_response_code == 200) {

  echo "Email Successfully Sent<br>";

  echo "<pre>";
  print_r($result);
  echo "</pre>";

  echo "Result: " . $result->http_response_code . "<p>";

} else {
   echo "Error sending email<br>";
}

} catch(Exception $e) {
  // Mandrill errors are thrown as exceptions
  echo "Error occured: " . $e->getMessage() . "<br>";
}

`

from mailgun-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.