Solved

PHP form mail question

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
File submission to SQL Server 1 39
PHP Undefined Index in HTML Form? 2 32
Form Processing in PHP 11 32
Why my select dropdown does not work? 8 27
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

895 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

15 Experts available now in Live!

Get 1:1 Help Now