问题
I am successully able to send emails via Amazon SES with the code below, but I am trying to set a return path and it doesnt work. When i use ->setReturnPath('bounce@example.com') the emails do not send at all. Can anyone shed some light why, or know how to get it to work? Any help would be great!
This is the latest swiftmailer (4.2.2)
require_once 'lib/swift_required.php';
require_once 'classes/Swift/Transport/AWSTransport.php';
require_once 'classes/Swift/AWSTransport.php';
require_once 'classes/Swift/AWSInputByteStream.php';
define( 'AWSAccessKeyId', 'XXXXX' );
define( 'AWSSecretKey', 'XXXXX' );
//Create the Transport
$transport = Swift_AWSTransport::newInstance( AWSAccessKeyId, AWSSecretKey );
$transport->setDebug( true ); // Print's the response from AWS for debugging.
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance( $transport );
//Create the message
$message = Swift_Message::newInstance()
->setSubject( 'Sample Subject' )
->setFrom( array( 'test@example.com' ) )
->setTo( array( 'to@someone.com' ) )
->setBody( $message_body, 'text/html' )
->addPart( "Please use a HTML compatible web browser to view this email.", 'text/plain' );
$mailer->send( $message );
回答1:
You can use this Swiftmailer function:
$message = Swift_Message::newInstance();
$headers = $message->getHeaders();
$headers->addPathHeader('Your-Header-Name', 'person@example.org');
回答2:
I've just tried it with similar code, and it worked. swiftmailer is now up to version 4.3.0, so it could be something fixed in that. Otherwise about the only difference in my code is I don't have the addPart() that you have.
Also, had you checked your php error logs? :-)
来源:https://stackoverflow.com/questions/13094250/swiftmailer-using-setreturnpath