How to add a reply-to and a from-name header with SendGrid php library

喜你入骨 提交于 2020-01-11 10:48:13

问题


This might be a silly question, but I've looked here, here and here, and there is no mentioning whatsoever about those simple functionality.

Can I user the addHeader method for this cause?.

Thanks in advance for any help!.


回答1:


Without more info about how you're actually sending the email (web?, smtp?, libraries?, etc), it's hard to give you a concise answer. That said, one of these three options should work:

1) If you're sending over HTTP with the web API

You can actually just add two extra parameters to your POST body, fromname and replyto, and send them along with the normal to, from, subject, etc.

Docs here: http://sendgrid.com/docs/API_Reference/Web_API/mail.html

2) If you're sending over SMTP with the PHP library

The PHP helper library (found here) has two helper methods, setReplyTo and setFromName to help you with that.

$mail = new SendGrid\Mail();
$mail->addTo('foo@bar.com')->
     setReplyTo('someone.else@example.com')->
     setFromName('John Doe')->
     ...

3) If you're sending with SwiftMailer

SwiftMailer is a popular SMTP library for PHP. It has it's own helper methods from Reply to and From name. You can find more info in the docs (see setReplyTo and setFrom)

http://swiftmailer.org/docs/messages.html#the-structure-of-a-message



来源:https://stackoverflow.com/questions/16190132/how-to-add-a-reply-to-and-a-from-name-header-with-sendgrid-php-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!