In the php.net example for mail()
, two different addresses are used for $to
and the additional header information "To: ...":
<?php
// multiple recipients
$to = '[email protected]' . ', '; // note the comma
$to .= '[email protected]';
$subject = 'Birthday Reminders for August';
// message
$message = '<html> ... </html>';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
So my question is: you need to provide $to
for the syntax of mail()
, however you cannot use the format Name <[email protected]>
, this you can only do in the additional header information, right?
So first, why does the example on php.net send the mail to 4 different people (because they use different e-mail addresses for $to
and for the header information), this really irritates me!?
And secondly, if I want to send the mail to only 1 person (and only 1 time) and I want to use the format Name <[email protected]>
, how should I do that? Use it in $to
as well as the header information? Will the person then receive the e-mail twice?
Recommend you to use PHP Mailer class instead of internal mail() function. There are several reasons to use PHP Mailer:
The $to-Parameter describes the Envelope-Recipient (who will get the mail). The to-Header is basically for the email-Application to show who got the mail.
The Mail-Envelope doesn't know about To, Cc or BCc; they are all recipients.
The Mail-Headers are for the recipients to know who also got the mail.
Some Mail-Servers send the mail to all given adresses (both: $to and to-header), some ignore the to-header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With