Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
814 views
in Technique[技术] by (71.8m points)

php - How to set 'FROM' property using Swiftmailer with Gmail?

<?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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...