PHP Sendgrid-发件人名称未通过邮件发送

时间:2018-11-21 21:19:18

标签: php sendgrid

我正在使用PHP Sendgrid。.一切正常。.但是问题是

我无法以某种方式添加Sender Namefrom email。我认为它没有捕获headers或我不知道的东西。

P.S:我已经在单独的服务器上执行了此代码,并且可以正常工作。但是,当我尝试使用相同的代码从另一台服务器发送邮件时,它将发送电子邮件,但未设置/显示发件人名称。我在使用Laravel 4是服务器方面的问题吗?请指导

$headers = "From: Coffe Email" . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

sendMail("myemail","mysubject","msg", $headers,$from="admin@email.com", "admin");

功能定义(sendMail):

function sendMail($to, $subject, $message, $headers, $from = "", $from_name="", $to_name="")
     { 
    require($_SERVER['DOCUMENT_ROOT']."/../sendgrid-php/sendgrid-php.php");
            $email = new \SendGrid\Mail\Mail();
            $email->setFrom($from, $from_name);
            $email->setSubject($subject);
            $email->addTo($to, $to_name);
            $email->addContent("text/plain", strip_tags($message));
            $email->addContent("text/html", $message);
            $sendgrid = new \SendGrid($settings->send_grid_user);
            try {
                $response = $sendgrid->send($email);
                print $response->statusCode() . "\n";
                print_r($response->headers());
                print $response->body() . "\n";
            } catch (Exception $e) {
                echo 'Caught exception: '. $e->getMessage() ."\n";
            }

    }

0 个答案:

没有答案