sendgrid / sendgrid-php

The Official Twilio SendGrid PHP API Library
https://sendgrid.com
MIT License
1.49k stars 623 forks source link

must be an instance of SendGrid\Mail\From or a valid email address #1050

Closed pdm-house closed 3 years ago

pdm-house commented 3 years ago

Issue Summary

I am getting this issue 2,3 time when sending an email

Code Snippet

require 'vendor/autoload.php';
        $email = new \SendGrid\Mail\Mail();
        $email->setFrom($this->ecomhut->getConfig('salesEmail'));
        $email->setSubject($subject);

        $email->addTo($data['email']);

        //$email->addBcc($this->ecomhut->getConfig('supportEmail'));

        $email->addBcc($this->ecomhut->getConfig('ForwarderEmail'));

        $email->setReplyTo($this->ecomhut->getConfig('supportEmail'),NULL);

        $email->addContent(
            "text/html", $template
        );

        $sendgrid = new \SendGrid($this->SENDGRID_API_KEY);

        try {
            $response = $sendgrid->send($email);

        } catch (Exception $e) {

           log_message('error', "Email Not Send form admin agianst ".$data['email']." \n" .print_r($response));

           return false;
        }
        return true;

Exception/Log

Exception: "$email" must be an instance of SendGrid\Mail\From or a valid email address public_html/vendor/sendgrid/sendgrid/lib/helper/Assert.php 61

Technical details:

shwetha-manvinkurke commented 3 years ago

@pdm-house is the From address in the proper email address format?

pdm-house commented 3 years ago

@pdm-house is the From address in the proper email address format?

Yes, sales@site.com this is the format in setFrom

pdm-house commented 3 years ago

@pdm-house is the From address in the proper email address format?

Thank You mate, on email variable there is space after email. fixed now...!