SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast whitecreek's Avatar
    Join Date
    Aug 2011
    Location
    Madrid, Spain
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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:

    Code:
    <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:

    Code:
    <?php
    
    $myemail  = "myemail@whatever.es";
    $myemail. = $email;
    
    $email   = $_POST['email'];
    $subject = "The sun is shinning";
    $headers= 'MIME-Version: 1.0' . "\r\n";
    $headers.= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $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:

    Code:
    $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.

  2. #2
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    why have you got a dot in the variable name?

  3. #3
    SitePoint Enthusiast whitecreek's Avatar
    Join Date
    Aug 2011
    Location
    Madrid, Spain
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:

    Code:
    $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.

  4. #4
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Each day is a learning experience.

  5. #5
    SitePoint Enthusiast whitecreek's Avatar
    Join Date
    Aug 2011
    Location
    Madrid, Spain
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

    Code:
    $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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •