?
Solved

PHP form mail question

Posted on 2014-04-14
5
Medium Priority
?
504 Views
Last Modified: 2014-04-15
Trying to get this form sent to multiple recipients, I dont know php but shouldnt this work?  


function emailFormSubmission()
{
      $to  = 'me@home.com' . ', ';
      $to .= 'you@home.com';
      $subject = 'Message from contact form';

---------------------------------------------------------------

the below code works when sending to a single address:
function emailFormSubmission()
{
      $to = 'you@home.com';
      $subject = 'Message from contact form';

--------------------------------

but I need to send to 2 address.

Thanks!
0
Comment
Question by:Bang-O-Matic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 39999262
Have you tried this?
function emailFormSubmission()
{
      $to = 'you@home.com, me@home.com';
      $subject = 'Message from contact form';
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39999298
First, Isuggest you to read this article: And by the way, I am New to PHP

About multiple emails, you can use PhpMailer or you can iterate through an array:

Trivial example:
function emailFormSubmission()
{
      $to = array('me@home.com', 'you@home.com');
      $subject = 'Message from contact form';
      $message = 'message';
      foreach ($to as $recipient)
      {
            mail($recipient, $subject, $message);
      }
}

Open in new window

0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 39999373
Please don't link to PHPMailer on Worxware; It's not been on there for years. It's now on GitHub.

Secondly, avoid calling mail() yourself. You'll probably be doing it wrong - use a library.

If you're sending the same message to both people, if they know each other, just add both as 'to' recipients of the same message, or CC one of them. If they don't, either use BCC or send two separate messages. There are plenty of code examples in the PHPMailer repo.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39999427
And even if that code would work, the variables you are using will only be 'local', not 'global' and be invisible to any other routines.
0
 

Author Closing Comment

by:Bang-O-Matic
ID: 40002588
Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question