Solved

PHP form mail question

Posted on 2014-04-14
5
454 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
5 Comments
 
LVL 34

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 30

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:Squinky
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 82

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
The viewer will learn how to dynamically set the form action using jQuery.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now