PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 23rd, 2002, 03:22 AM
Jeremy Jeremy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Jeremy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Trying to send email to multiple addresses at once.

Hello. I am trying to put together a form that will send email to several people at once. The email addresses, to which a prewritten message will be sent, will be specified by the site visitor. I am using this for a "Refer your friends to this website" type of purpose. The visitor will put in several names and corresponding email addresses (up to about 8 to 10) and I want the mail to all go out at the same time when the visitor hits the "submit" button. The form itself has several fields for inputting friends' addresses. I have assigned a unique variable to each of the "friends" form fields. I just need a way to take these several email variables and note in the PHP script to email to all of them upon clicking the "submit" button once.

Here is a sample form I'm using right now to test things:

http://www.dwellingproductions.com/...ferfriends.html

You can take a look at this to visualize the potential interface.

Below are my attempts at scripting this. So far, I cannot get it to work. I know I've got to be close though. How can I do this?

Thanks, in advance, for the help.

Jeremy

This was my first attempt. This works for one email address, but I cannot figure out how to allow there to be multiple addresses sent at once:

<?php
$ToEmail = "$emailFriend1"; //The first of several, hopefully
$ToName = "$nameFriend1"; //The first of several, hopefully
$ToSubject = "Did this work?";
$EmailBody = "The following individual thought you would like to check out our website.nnName: $txtNamenEmail: $txtEmailnURL: $txtURLnComments:n$txtComments";
$EmailFooter = "nnMessage Complete";
$Message = $EmailBody.$EmailFooter;
mail($ToEmail, $ToSubject, $Message, "From: $txtEmail");
Print "_root.form.txtStatus=Complete - Your mail has been sent!";
?>

This is my attempt using an array:

<?php
$to = array();
$to[0] = "emailFriend1";
$to[1] = "emailFriend2";
$ToSubject = "Did this work?";
$EmailBody = "Message from Refer Friends FormnnName: $txtNamenEmail: $txtEmailnURL: $txtURLnComments:n$txtComments";
$EmailFooter = "nnMessage Complete";
$Message = $EmailBody.$EmailFooter;
for( $ToEmail = $to) {
mail($ToEmail, $ToSubject, $Message, "From: $txtEmail");
}
Print "_root.form.txtStatus=Complete - Your mail has been sent!";
?>

Reply With Quote
  #2  
Old August 24th, 2002, 12:46 AM
Jeremy Jeremy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Jeremy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Trying to send email to multiple addresses at once.

OK. After some more attempts at this, here's where I'm at. With the script below, I'm getting a response from the script that the mail has been sent. However, nothing actually gets sent. So, obviously the syntax is legal enough to return the "print" statement. But, for some reason, the script is not executing as desired. Could someone double check the script below to see if there an error in syntax? Otherwise, the method seems to be exactly what is needed in this situation. I can't, for the life of me, figure out why it's not actually sending the emails.

I truly appreciate the assistance.

Jeremy

<?php

// create the arrays (email, name)
$email = array();
$name = array();

//find out if the form fields (email, name) have values
if(isset($emailFriend1)) {
$name[0] = $nameFriend1;
$email[0] = $emailFriend1;
}
if(isset($emailFriend2)) {
$name[1] = $nameFriend2;
$email[1] = $emailFriend2;
}

// find out the number in the array
$arr_num = count($email);

// loop that amount
for ($i=0; $i<=$arr_num; $i++) {
$to = '"$name[$i]"<$email[$i]>';
$ToSubject = "Did this work?";
$EmailBody = "Message from Refer Friends FormnnName: $txtNamenEmail: $txtEmailnURL: $txtURLnComments:n$txtComments";
$EmailFooter = "nnMessage Complete";
$Message = $EmailBody.$EmailFooter;
mail($to, $ToSubject, $Message, "From: $txtEmail");
}

Print "_root.form.txtStatus=Complete - Your mail has been sent!";
?>

Reply With Quote
  #3  
Old August 24th, 2002, 01:06 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: Trying to send email to multiple addresses at once.

The mail statement can send to multiple people seperated by comma's, therefore all you really need to do is check whether or not the e-mails provided are in fact valid e-mail addresses.. so have people enter their friends e-mails seperated by comma's, and then verify it before submitting.
php Code:
Original - php Code
  1.  
  2. <?php
  3. $to = "one@one.com, two@two.com, three@three.com";
  4. $subject = "Did this work?";
  5. $message = "this is a test message";
  6. $headers .= "From: you@yourhost.comrn";
  7.  
  8. $bits = explode(", ", $to);
  9. foreach($bits as $value)
  10. {
  11.     //check if $value's are properly formatted
  12.     // if not then exit with error
  13.     // if so then - mail($to, $subject, $message, $headers);
  14. }
  15. ?>

Reply With Quote
  #4  
Old August 24th, 2002, 07:40 PM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,253 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 4
Send a message via Yahoo to bakertrg
RE: Trying to send email to multiple addresses at once.

Sometimes php mail() is rejected because the headers are not properly formatted.

B

Reply With Quote
  #5  
Old August 25th, 2002, 09:29 AM
Jeremy Jeremy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Jeremy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Trying to send email to multiple addresses at once.

notepad and bakertrg,

Thanks for the replies. I actually want to allow the visitor to use a separate form field to input each of their friends' email addresses. Is there a way I can take advantage of the comma seperated technique without requiring the site visitor to separate the emails by commas?

Thanks so much for the assistance.

Reply With Quote
  #6  
Old August 25th, 2002, 10:22 AM
Gipz Gipz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Stockholm, Sweden
Posts: 98 Gipz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Gipz
RE: Trying to send email to multiple addresses at once.

Check out the mail class at www.phpguru.com ...

Works great!

Reply With Quote
  #7  
Old August 27th, 2002, 03:45 AM
Jeremy Jeremy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Jeremy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Trying to send email to multiple addresses at once.

hmmm... phpguru.com seems to be down right now. I hope it comes back up.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Trying to send email to multiple addresses at once.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway