使用 Gmail 进行 SMTP 时,您可以设置不同的“发件人”吗?地址?

发布于 2024-10-26 03:24:06 字数 193 浏览 4 评论 0原文

我正在使用 Swift Mailer 406 发送电子邮件。我连接到我的 smtp.gmail.com 帐户,然后我这样做:

->setFrom(array($from => $fromname))

但是发送的电子邮件收到了原始的 gmail 帐户电子邮件。

我可以改变它吗?

I am using Swift Mailer 406 for sending emails. I connect to my smtp.gmail.com account and then I do:

->setFrom(array($from => $fromname))

But the emails sent got the original gmail account email.

Can I change it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

物价感观 2024-11-02 03:24:06

gmail 不允许您使用随机发件人地址。您必须在 Gmail 设置中添加并验证您想要使用的地址:

Settings -> Accounts -> Send mail as -> Add another email address you own

gmail doesn't allow you to use random From addresses. You have to add and validate the address you'd like to use in the gmail settings:

Settings -> Accounts -> Send mail as -> Add another email address you own
ヤ经典坏疍 2024-11-02 03:24:06
$email=$entity->getEmail();
->setFrom(array('your fix [email protected]' => $email))
$email=$entity->getEmail();
->setFrom(array('your fix [email protected]' => $email))
余生一个溪 2024-11-02 03:24:06

在您的Parameters.yml 中,您应该进行以下配置:

parameters:
database_host: 127.0.0.1
database_port: null
database_name: your db name
database_user: root
database_password: null
mailer_transport: smtp
mailer_host: smtp.gmail.com
mailer_user: your fix [email protected]
mailer_password: your password of your fix adress
mailer_port: 465
mailer_encryption: ssl
auth_mode:         login
secret: 3556f3fb752a82ce0ee9c419ef793b7a707f324a

在您的联系人控制器中,您应该添加此配置来修复 swiftmailer 的 setfrom() 功能:

if ($form->isValid()) {
    $em = $this->getDoctrine()->getManager();
    $subject = $entity->getSubject();
    $name=$entity->getName();
    $email=$entity->getEmail();
    $body=$entity->getBody();
    $message = \Swift_Message::newInstance('here')
        ->setSubject("Shoppify email from ".$name." Subject ".$subject)
        ->setFrom(array('your fix [email protected]' => $email))
        ->setTo('your adress [email protected]')
        ->setBody($body);
    $this->get('mailer')->send($message);
    $em->persist($entity);
    $em->flush();
    return $this->redirect($this->generateUrl('email_sended'));
}

In your Parameters.yml you should make this configuration:

parameters:
database_host: 127.0.0.1
database_port: null
database_name: your db name
database_user: root
database_password: null
mailer_transport: smtp
mailer_host: smtp.gmail.com
mailer_user: your fix [email protected]
mailer_password: your password of your fix adress
mailer_port: 465
mailer_encryption: ssl
auth_mode:         login
secret: 3556f3fb752a82ce0ee9c419ef793b7a707f324a

And in your contact controller you should add this to fix setfrom() function of swiftmailer:

if ($form->isValid()) {
    $em = $this->getDoctrine()->getManager();
    $subject = $entity->getSubject();
    $name=$entity->getName();
    $email=$entity->getEmail();
    $body=$entity->getBody();
    $message = \Swift_Message::newInstance('here')
        ->setSubject("Shoppify email from ".$name." Subject ".$subject)
        ->setFrom(array('your fix [email protected]' => $email))
        ->setTo('your adress [email protected]')
        ->setBody($body);
    $this->get('mailer')->send($message);
    $em->persist($entity);
    $em->flush();
    return $this->redirect($this->generateUrl('email_sended'));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文