How to set 'FROM' property using Swiftmailer with Gmail?
Asked Answered
B

2

5
<?php
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
  ->setUsername('[email protected]')
  ->setPassword('password')
  ;
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('HomeWork')
  ->setFrom(array('[email protected]' => 'NAME'))
  ->setTo(array('[email protected]'=> 'NAME'))
  ->setBody('Test Message Body')
  ;
$mailer->send($message);
?>

It works but sender is '[email protected]'. How can I specify any other email address in order to send fake email?

Broken answered 2/1, 2013 at 20:8 Comment(0)
A
8

Gmail disallows overriding the FROM name except from verfied email addresses that you prove to gmail you own. Either choose a different email server or go to your gmail settings and change it to another valid email address that you can receive email from.

Avaavadavat answered 2/1, 2013 at 20:16 Comment(0)
P
2

You need to set the outgoing emailaddress in gmail. Gmail changes the emailaddress to the address in your gmail if it is not in the list of emailaddresses where you can sent from.

Gmail -> settings -> Send mail as -> Add another email address you own

Pomatum answered 2/1, 2013 at 20:12 Comment(3)
Perhaps using a reply-to could accomplish OP's needs?Bradytelic
No, gmail removes the reply-to headers.Pomatum
I added my another email, but it doesn't work. Original sender's address is still visible.Broken

© 2022 - 2024 — McMap. All rights reserved.