向收件箱中的电子邮件用户显示名称

时间:2015-08-13 11:25:57

标签: php email sendmail sendgrid

我正在使用sendgrid向我的用户发送电子邮件。以前它工作正常,但是在过去10-20天没有对代码进行任何更改的情况下,我发现用户会在收件箱的from字段中看到电子邮件地址而不是名称。

这是我的代码:

<?php

$url = 'https://api.sendgrid.com/';
$user = 'USERNAME';
$pass = 'PASSWORD';

$params = array(
'api_user'  => $user,
'api_key'   => $pass,
'to'        => 'example3@sendgrid.com',
'subject'   => 'testing from curl',
'html'      => 'testing body',
'text'      => 'testing body',
'from'      => '<domain name>example@sendgrid.com',  // see here 
 );
 $request =  $url.'api/mail.send.json';

 // Generate curl request
 $session = curl_init($request);
 // Tell curl to use HTTP POST
 curl_setopt ($session, CURLOPT_POST, true);
 // Tell curl that this is the body of the POST
 curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
 // Tell curl not to return headers, but do return the response
 curl_setopt($session, CURLOPT_HEADER, false);
 // Tell PHP not to use SSLv3 (instead opting for TLS)
 curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
 curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

 // obtain response
 $response = curl_exec($session);
 url_close($session);

 // print everything out
 print_r($response);

 ?>

问题是,用户应该在收件箱的from字段中获取域名而不是电子邮件,但他们会收到电子邮件。

我正在使用from这样的标签

     'from'      => '<domain name>example@sendgrid.com'

你能告诉我一件事吗?

1 个答案:

答案 0 :(得分:1)

你可以使用fromname param,如:

'from' => 'email@domain.com',
'fromname' => 'Your Name'