Confirmation email to multiple recipients including $email

Hi there

I hope this post results in a easy-to-answer one. I’m sure it will.

What I’m busy with at the moment is pretty simple. I’m coding a basic html form with 1 only input text field. Here is the code for the form:



<form action="thanks.php" method="post" name="formulario2">
<input type="text" name="email" id="email" value="" />
<p><input type="button" value="Enviar" onclick="validar(this.checked)"/><input type="reset" name="borrar" value="Borrar"/></p>
</form>


This form is used to add email adresses to a newsletter list which I’ll be handling myself. And It is processed by the following “thanks.php” file:



<?php

$myemail  = "myemail@whatever.es";
$myemail. = $email;

$email   = $_POST['email'];
$subject = "The sun is shinning";
$headers= 'MIME-Version: 1.0' . "\\r\
";
$headers.= 'Content-type: text/html; charset=utf-8' . "\\r\
";
$headers.= "From: myemail2@whatever.es";

$message = "
Hi there
";

mail($myemail, $subject, $message, $headers);
?>


What I want this php file to do is to send an email (the same email actually) to 2 email recipients. One would be “myemail@whatever.es”. The second one would be whatever email inserted into the html form field with the id=“email”. When running the php file I get this error:

Parse error: syntax error, unexpected ‘=’ in …/thanks.php on line 5”, being this line 5:



$myemail. = $email;


I thought the problem would be I was calling $email - $myemail. = $email; - before posting it - $email = $_POST[‘email’]; -, so I changed the order… getting the same error. I might be writtng something wrong or missing something, or problably both. Im quite new to PHP I have to admit. Any help on where the problem might be?

Thanks very much in advance.

why have you got a dot in the variable name?

Hi Max Height,

Thanks for answering.

Well, I don’t remember exactly where, but I read this dot is used in PHP to list several instances of the same variable. I just tried it whithout the dot and the error is gone. The email is being sent, but only to $email, not to myemail@whatever.es. I guess it would be best to group both email adresses in the same string:

$myemail  = "myemail@whatever.es", $email;

but I’m not sure if this is the right syntax to do so. I’ll try and come back later. If anyone comes up with the right way to do it in the meantime, I’d appreciate that.

Thanks again.

The dot allows you to add to your variable. You could initially set $myemail = your personal email address. From your form get $email.

Now set $myemail . = “,” . $email

You should now have your email, a comma to separate the email addresses, and whatever was in the variable $email.

Hope this helps.

Hi CSU-Bill

I think I found the way to group actual email adresses together with variables within the same php variable… and it couldn’t be any more simple :stuck_out_tongue:

$myemail  = "myemail@whatever.es,$email";

It seems to be working just fine… but I’ll be back on this if I find any more problems!!

Thanks very much for your time. Regards.