Solved

PHP form mail question

Posted on 2014-04-14
5
491 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 500 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

729 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