我正在使用Swift Mailer 406发送电子邮件。我连接到我的smtp.gmail.com帐户然后我这样做:
->setFrom(array($from => $fromname))
但是发送的电子邮件收到了原始的gmail帐户电子邮件。
我可以更改吗?
答案 0 :(得分:16)
gmail不允许您使用随机的From地址。您必须添加并验证您要在Gmail设置中使用的地址:
Settings -> Accounts -> Send mail as -> Add another email address you own
答案 1 :(得分:0)
("")()
答案 2 :(得分:-1)
在您的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 adress@gmail.com
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 adress@gmail.com' => $email))
->setTo('your adress destionation@example.com')
->setBody($body);
$this->get('mailer')->send($message);
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('email_sended'));
}