This is probably an easy question but I am not sure the proper syntax.
I am sending an email to my client - but my client also wants that person to receive the emails once they hit submit.
Currently its a POST php form and it works fine - but need to include the POST-email address that was entered into the form.
$from_email = $_POST['emailAddress'];
$to = 'owen@gmail.com';
AND I have mail($to, $subject, $message, $header..
So how do I rewrite the code:
$to = 'owenpiccirillo@gmail.com';
to have also send to the email submitted in the form? because this works.
$to = 'owen@gmail.com, whatever@aol.com';
but this doesnt work....
$to = 'owen@gmail.com' . $from_email;
Thanks in advance -O
You need a comma and space in the $to
concatenation:
NOT
$to = 'owen@gmail.com' . $from_email;
// results in 'owen@gmail.comwhatever@aol.com'
but THIS
$to = 'owen@gmail.com, ' . $from_email;
// results in 'owen@gmail.com, whatever@aol.com'
If this works:
$to = 'owen@gmail.com, whatever@aol.com';
then what exactly is the issue? The reason this doesn't work:
$to = 'owen@gmail.com' . $from_email;
is because there's no comma separating the values. So it would evaluate to:
$to = 'owen@gmail.comwhatever@aol.com';
which isn't a valid email address.
This is because the .
is concatenating the two addresses together. So if you do an echo
or print_r
you would see something like this:
owen@gmail.comwhatever@aol.com
You need to add a comma:
// Value will be injected into the string with double quotes.
$to = "owen@gmail.com, $from_email";
Alternatively, you can use CC and BCC to send copies.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.