Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
addReplyTo example
break
;
case
'recipientsBcc':
$mailAddresses
= \
is_array
(
$value
)
?
$value
:
[
$value
=>
$value
]
;
$this
->
assertValidAddresses
(
array_keys
(
$mailAddresses
)
)
;
$mail
->
addBcc
(
...
$this
->
formatMailAddresses
(
$mailAddresses
)
)
;
break
;
case
'replyTo':
$mailAddresses
= \
is_array
(
$value
)
?
$value
:
[
$value
=>
$value
]
;
$this
->
assertValidAddresses
(
array_keys
(
$mailAddresses
)
)
;
$mail
->
addReplyTo
(
...
$this
->
formatMailAddresses
(
$mailAddresses
)
)
;
break
;
case
'returnPath':
$mailAddresses
= \
is_array
(
$value
)
?
$value
:
[
$value
=>
$value
]
;
$this
->
assertValidAddresses
(
array_keys
(
$mailAddresses
)
)
;
$mail
->
returnPath
(
...
$this
->
formatMailAddresses
(
$mailAddresses
)
)
;
}
}
return
$mail
;
}
$transport
=
new
SendinblueApiTransport
(
'ACCESS_KEY',
$client
)
;
$transport
->
setPort
(
8984
)
;
$mail
=
new
Email
(
)
;
$mail
->
subject
(
'Hello!'
)
->
to
(
new
Address
(
'
[email protected]
', 'Saif Eddin'
)
)
->
from
(
new
Address
(
'
[email protected]
', 'Fabien'
)
)
->
text
(
'Hello here!'
)
->
html
(
'Hello there!'
)
->
addCc
(
'
[email protected]
'
)
->
addBcc
(
'
[email protected]
'
)
->
addReplyTo
(
'
[email protected]
'
)
->
addPart
(
new
DataPart
(
'body'
)
)
;
$message
=
$transport
->
send
(
$mail
)
;
$this
->
assertSame
(
'foobar',
$message
->
getMessageId
(
)
)
;
}
}
use
Symfony\Component\HttpFoundation\Response;
use
Symfony\Component\Mailer\MailerInterface;
use
Symfony\Component\Mime\Address;
use
Symfony\Component\Mime\Email;
use
Symfony\Component\Mime\Part\DataPart;
class
EmailController
{
public
function
indexAction
(
MailerInterface
$mailer
)
{
$mailer
->
send
(
(
new
Email
(
)
)
->
to
(
'
[email protected]
'
)
->
from
(
'
[email protected]
'
)
->
subject
(
'Foo'
)
->
addReplyTo
(
'
[email protected]
'
)
->
addCc
(
'
[email protected]
'
)
->
text
(
'Bar!'
)
->
html
(
'<p>Foo</p>'
)
->
addPart
(
new
DataPart
(
file_get_contents
(
__FILE__
)
, 'foobar.php'
)
)
)
;
$mailer
->
send
(
(
new
Email
(
)
)
->
to
(
'
[email protected]
', '
[email protected]
'
)
->
from
(
'
[email protected]
'
)
->
subject
(
'Foo'
)
->
addReplyTo
(
new
Address
(
'
[email protected]
', 'Fabien Potencier'
)
)
->
addCc
(
'
[email protected]
'
)
->
text
(
'Bar!'
)
->
html
(
'<p>Foo</p>'
)
switch
(
$address_header
)
{
case
'to':
$phpmailer
->
addAddress
(
$address
,
$recipient_name
)
;
break
;
case
'cc':
$phpmailer
->
addCc
(
$address
,
$recipient_name
)
;
break
;
case
'bcc':
$phpmailer
->
addBcc
(
$address
,
$recipient_name
)
;
break
;
case
'reply_to':
$phpmailer
->
addReplyTo
(
$address
,
$recipient_name
)
;
break
;
}
}
catch
(
PHPMailer\PHPMailer\Exception
$e
)
{
continue
;
}
}
}
// Set to use PHP's mail().
$phpmailer
->
isMail
(
)
;
$helene
=
new
Address
(
'
[email protected]
'
)
;
$thomas
=
new
Address
(
'
[email protected]
', 'Thomas'
)
;
$caramel
=
new
Address
(
'
[email protected]
'
)
;
$this
->
assertSame
(
$e
,
$e
->
replyTo
(
'
[email protected]
',
$helene
,
$thomas
)
)
;
$v
=
$e
->
getReplyTo
(
)
;
$this
->
assertCount
(
3,
$v
)
;
$this
->
assertEquals
(
new
Address
(
'
[email protected]
'
)
,
$v
[
0
]
)
;
$this
->
assertSame
(
$helene
,
$v
[
1
]
)
;
$this
->
assertSame
(
$thomas
,
$v
[
2
]
)
;
$this
->
assertSame
(
$e
,
$e
->
addReplyTo
(
'
[email protected]
',
$caramel
)
)
;
$v
=
$e
->
getReplyTo
(
)
;
$this
->
assertCount
(
5,
$v
)
;
$this
->
assertEquals
(
new
Address
(
'
[email protected]
'
)
,
$v
[
0
]
)
;
$this
->
assertSame
(
$helene
,
$v
[
1
]
)
;
$this
->
assertSame
(
$thomas
,
$v
[
2
]
)
;
$this
->
assertEquals
(
new
Address
(
'
[email protected]
'
)
,
$v
[
3
]
)
;
$this
->
assertSame
(
$caramel
,
$v
[
4
]
)
;
$e
=
new
Email
(
)
;
$e
->
addReplyTo
(
'
[email protected]
',
$caramel
)
;
$this
->
assertCount
(
2,
$e
->
getReplyTo
(
)
)
;
$transport
=
new
BrevoApiTransport
(
'ACCESS_KEY',
$client
)
;
$transport
->
setPort
(
8984
)
;
$mail
=
new
Email
(
)
;
$mail
->
subject
(
'Hello!'
)
->
to
(
new
Address
(
'
[email protected]
', 'Saif Eddin'
)
)
->
from
(
new
Address
(
'
[email protected]
', 'Fabien'
)
)
->
text
(
'Hello here!'
)
->
html
(
'Hello there!'
)
->
addCc
(
'
[email protected]
'
)
->
addBcc
(
'
[email protected]
'
)
->
addReplyTo
(
'
[email protected]
'
)
->
addPart
(
new
DataPart
(
'body'
)
)
;
$message
=
$transport
->
send
(
$mail
)
;
$this
->
assertSame
(
'foobar',
$message
->
getMessageId
(
)
)
;
}
}
public
function
getFrom
(
)
: array
{
return
$this
->message->
getFrom
(
)
;
}
/** * @return $this */
public
function
addReplyTo
(
string
$address
)
:
static
{
$this
->message->
addReplyTo
(
$address
)
;
return
$this
;
}
/** * @return Address[] */
public
function
getReplyTo
(
)
: array
{
return
$this
->message->
getReplyTo
(
)
;
}
}
)
;
$transport
=
new
MailerSendApiTransport
(
'ACCESS_KEY',
$client
)
;
$mail
=
new
Email
(
)
;
$mail
->
subject
(
'Test subject'
)
->
to
(
new
Address
(
'
[email protected]
', 'Test to name'
)
)
->
from
(
new
Address
(
'
[email protected]
', 'Test from name'
)
)
->
addCc
(
'
[email protected]
'
)
->
addBcc
(
'
[email protected]
'
)
->
addReplyTo
(
'
[email protected]
'
)
->
text
(
'Lorem ipsum.'
)
->
html
(
'<html><body><p>Lorem ipsum.</p></body></html>'
)
;
$message
=
$transport
->
send
(
$mail
)
;
$this
->
assertSame
(
'test_message_id',
$message
->
getMessageId
(
)
)
;
}
public
function
testSendEmailWithAttachment
(
)
{
$client
=
new
MockHttpClient
(
function
Dstring
$method
, string
$url
, array
$options
)
: ResponseInterface
{